java import 类重复_从另一个Java类调用方法会创建重复的JPanel...

当我尝试从JPanel4中的JPanel2调用方法时,按下按钮后它不会显示JFrame中的任何更改,但是当我尝试将按钮放入JPanel2中时,一切正常.所以我的问题是,正如我在标题中所述-我是否创建了重复的JPanel?我对Java还是很陌生,因此不胜感激.

主要

package tellimine;

import java.awt.Dimension;

import java.awt.EventQueue;

import java.awt.GridBagConstraints;

import java.awt.GridBagLayout;

import java.awt.Insets;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.JFrame;

public class Tellimine extends JFrame{

public Tellimine(){

super("Tellimine");

}

public void looFrame() throws Exception{

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setPreferredSize(new Dimension(800, 310));

this.setLayout(new GridBagLayout());

GridBagConstraints c = new GridBagConstraints();

JPanel2 panel2 = new JPanel2();

c.fill = GridBagConstraints.HORIZONTAL;

c.insets = new Insets(0,0,0,0);

c.weightx = 1.0;

c.gridx = 0;

c.gridy = 1;

this.add(panel2, c);

JPanel4 panel4 = new JPanel4();

c.fill = GridBagConstraints.HORIZONTAL;

c.ipady = 0;

c.weighty = 1.0;

c.anchor = GridBagConstraints.PAGE_END;

c.gridx = 0;

c.gridwidth = 2;

c.gridy = 3;

this.add(panel4, c);

this.setVisible(true);

this.pack();

}

public static void main(String[] args) throws Exception{

Class.forName("cubrid.jdbc.driver.CUBRIDDriver");

final Tellimine raam = new Tellimine();

EventQueue.invokeLater(new Runnable() {

@Override

public void run() {

try {

raam.looFrame();

} catch (Exception ex) {

Logger.getLogger(Tellimine.class.getName()).log(Level.SEVERE, null, ex);

}

}

});

}

}

JPanel2

package tellimine;

import java.awt.GridLayout;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import javax.swing.JFormattedTextField;

import javax.swing.JLabel;

import javax.swing.JPanel;

public class JPanel2 extends JPanel{

private Connection conn;

Integer suurus;

JLabel tellimus, tk_nr;

JFormattedTextField tellija, kuupaev;

Statement stmt = null;

ResultSet rs = null;

public JPanel2() throws SQLException{

super();

panel2();

}

public static Connection connect() {

Connection conn = null;

try{

conn = DriverManager.getConnection("jdbc:cubrid:localhost:33000:Access::","dba","qwerty");

}

catch ( Exception e ) {

System.err.println("SQLException : " + e.getMessage());

}

return conn;

}

public void panel2() throws SQLException{

conn=connect();

stmt = conn.createStatement();

rs = stmt.executeQuery("SELECT * FROM yldandmed");

rs.next();

tellimus = new JLabel();

tk_nr = new JLabel();

tellija = new JFormattedTextField();

kuupaev = new JFormattedTextField();

yldandmed();

this.setLayout(new GridLayout(3,5));

this.add(new JLabel("Tellimuse ID"));

this.add(tellimus);

this.add(new JLabel("Tellija:"));

this.add(tellija);

this.add(new JLabel(""));

this.add(new JLabel("Sissekandekuup?ev"));

this.add(kuupaev);

this.add(new JLabel("T??k?su nr:"));

this.add(tk_nr);

this.add(new JLabel(""));

this.add(new JLabel("Tellimise Detailid"));

this.add(new JLabel(""));

this.add(new JLabel(""));

this.add(new JLabel(""));

}

public void yldandmed() throws SQLException{

tellimus.setText(rs.getString("tel_id"));

System.out.println(rs.getString("tellija"));

tellija.setText(rs.getString("tellija"));

kuupaev.setText(rs.getString("kuupaev"));

tk_nr.setText(rs.getString("tk_nr"));

}

}

JPanel4

package tellimine;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.SQLException;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.JButton;

import javax.swing.JPanel;

public class JPanel4 extends JPanel{

JPanel2 paneel = new JPanel2();

public JPanel4() throws Exception{

super();

panel4();

}

private void panel4() throws SQLException{

JButton uuenda = new JButton("

this.add(uuenda);

uuendanupp uuendus = new uuendanupp();

uuenda.addActionListener(uuendus);

JButton lisa = new JButton(">");

this.add(lisa);

lisanupp lisamine = new lisanupp();

lisa.addActionListener(lisamine);

}

private class uuendanupp implements ActionListener{

public void actionPerformed(ActionEvent e){

System.out.println("

}

}

private class lisanupp implements ActionListener{

public void actionPerformed(ActionEvent e){

try {

paneel.rs.next();

paneel.yldandmed();

System.out.println(">");

} catch (SQLException ex) {

Logger.getLogger(JPanel4.class.getName()).log(Level.SEVERE, null, ex);

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值