publicclassGUIimplementsActionListener{JFrameframe;JLabellabel1,label2,label3;JPanelpanel1,panel2;JButtonbutton;JTextFieldtextfield1,textfield2;publicstaticvoidmain(Strin...
public class GUI implements ActionListener {
JFrame frame;
JLabel label1,label2,label3;
JPanel panel1,panel2;
JButton button;
JTextField textfield1,textfield2;
public static void main(String[]args){
GUI gui=new GUI();
gui.go();
}
private void go() {
frame=new JFrame();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel1=new JPanel();
panel1.setLocation(0, 100);
panel1.setBackground(Color.blue);
frame.getContentPane().add(BorderLayout.CENTER,panel1);
label1=new JLabel("进销存系统");
label1.setSize(100, 100);
panel1.add(label1);
panel2=new JPanel();
panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));
label2=new JLabel("用户名");
label3=new JLabel("密码");
textfield1=new JTextField(20);
textfield1=new JTextField();
textfield2=new JTextField(20);
textfield2=new JTextField();
button=new JButton("登录");
button.addActionListener(this);
panel2.add(label2);
panel2.add(textfield1);
panel2.add(label3);
panel2.add(textfield2);
panel2.add(button);
frame.getContentPane().add(BorderLayout.EAST, panel2);
Mypanel drawPanel=new Mypanel();
frame.setVisible(true);
// TODO Auto-generated method stub
}
public void actionPerformed(ActionEvent e) {
frame.repaint();
// TODO Auto-generated method stub
}
class Mypanel extends JPanel{
public void paintComponent(Graphics g){
g.setColor(Color.black);
g.fillRect(0, 0, frame.getWidth(), frame.getHeight());
}
}
}
展开