import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class DianFeiSystem
{
public static void main(String args[])
{
DengLu denglu = new DengLu();
}
}class DengLu extends JFrame implements ActionListener
{
private JPanel denglu;
private JLabel lab1,lab2;
private TextField text1,text2;
private TextArea text3;
private Button button1,button2;
private ImageIcon ii;
private JLabel lab;
DengLu()
{
this.setBounds(300, 100, 340, 360);
this.setTitle("校院电费查询系统");
denglu = new JPanel();
lab1 = new JLabel("寝室号:");
lab2 = new JLabel("密码:");
text1 = new TextField(30);
text2 = new TextField(30);
text3 = new TextArea(12,35);
button1 = new Button("登陆查询");
button2 = new Button("不知道密码?");
denglu.add(lab1);
denglu.add(text1);
denglu.add(lab2);
denglu.add(text2);
denglu.add(button1);
denglu.add(button2);
denglu.add(text3);
button1.addActionListener(this);
button2.addActionListener(this);
ii = new ImageIcon("1.jpg");
lab = new JLabel(ii);
lab.setBounds(0, 0,ii.getIconWidth(), ii.getIconHeight());
this.getLayeredPane().setLayout(null);
this.getLayeredPane().add(lab, new Integer(Integer.MIN_VALUE));
this.setContentPane(denglu);
denglu.setOpaque(false);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == button1)
{
XianShi xianshi = new XianShi();
}
else if(e.getSource() == button2)
{
text1.setText("");
text2.setText("");
}
}
}代码如上,在事件e.getSource() == button1发生以后打开了一个新的窗体,但是我想在同事关闭原有窗体怎么做?
import java.awt.*;
import java.awt.event.*;public class DianFeiSystem
{
public static void main(String args[])
{
DengLu denglu = new DengLu();
}
}class DengLu extends JFrame implements ActionListener
{
private JPanel denglu;
private JLabel lab1,lab2;
private TextField text1,text2;
private TextArea text3;
private Button button1,button2;
private ImageIcon ii;
private JLabel lab;
DengLu()
{
this.setBounds(300, 100, 340, 360);
this.setTitle("校院电费查询系统");
denglu = new JPanel();
lab1 = new JLabel("寝室号:");
lab2 = new JLabel("密码:");
text1 = new TextField(30);
text2 = new TextField(30);
text3 = new TextArea(12,35);
button1 = new Button("登陆查询");
button2 = new Button("不知道密码?");
denglu.add(lab1);
denglu.add(text1);
denglu.add(lab2);
denglu.add(text2);
denglu.add(button1);
denglu.add(button2);
denglu.add(text3);
button1.addActionListener(this);
button2.addActionListener(this);
ii = new ImageIcon("1.jpg");
lab = new JLabel(ii);
lab.setBounds(0, 0,ii.getIconWidth(), ii.getIconHeight());
this.getLayeredPane().setLayout(null);
this.getLayeredPane().add(lab, new Integer(Integer.MIN_VALUE));
this.setContentPane(denglu);
denglu.setOpaque(false);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == button1)
{
XianShi xianshi = new XianShi();
}
else if(e.getSource() == button2)
{
text1.setText("");
text2.setText("");
}
}
}代码如上,在事件e.getSource() == button1发生以后打开了一个新的窗体,但是我想在同事关闭原有窗体怎么做?
{
XianShi xianshi = new XianShi();
this.dispose();
}