大工程之1,这个要真的练习20遍!

package talk_mouse;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class LoginJFrame extends JFrame implements ActionListener{

JLabel labUser=new JLabel("用户名:");//新建用户名标签

JTextField txtUser=new JTextField();//新建输入框

JLabel labPass=new JLabel("密码:");//新建密码标签

JPasswordField txtPass=new JPasswordField();

JButton btnLogin=new JButton("登录");

JButton btnCancel=new JButton("取消");

JButton btnReg=new JButton("注册");

LoginJFrame(){

this.setSize(250, 130);

btnLogin.addActionListener(this);

btnCancel.addActionListener(this);

btnReg.addActionListener(this);

JPanel panInput=new JPanel();

panInput.setLayout(new GridLayout(2,2));

panInput.add(labUser);

panInput.add(txtUser);

panInput.add(labPass);

panInput.add(txtPass);

JPanel panButton=new JPanel();

panButton.setLayout(new FlowLayout());

panButton.add(btnLogin);

panButton.add(btnCancel);

panButton.add(btnReg);

this.setLayout(new BorderLayout());

this.add(panInput,BorderLayout.NORTH);

this.add(panButton,BorderLayout.CENTER);

}

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

if(e.getActionCommand().equals("取消")) {

this.setVisible(false);

}

if(txtUser.getText().equals("周扬")&&txtPass.getText().equals("123456")) {

if(e.getActionCommand().equals("登录")) {

this.setVisible(false);

ChatJFrame chat=new ChatJFrame();

chat.setVisible(true);

}

}

}

}



package talk_mouse;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class ChatJFrame extends JFrame implements ActionListener{

JTextField txtInput=new JTextField();

JButton btnSend=new JButton("发送>");

JComboBox friendList=new JComboBox();

JTextArea txtRecord=new JTextArea();

JScrollPane scroll=new JScrollPane(txtRecord);

ChatJFrame(){

setSize(300,400);

JPanel panBtn=new JPanel();

panBtn.setLayout(new GridLayout(1,2));

panBtn.add(friendList);

panBtn.add(btnSend);

JPanel panInput=new JPanel();

panInput.setLayout(new GridLayout(2,1));

panInput.add(txtInput);

panInput.add(panBtn);

this.setLayout(new BorderLayout());

this.add(panInput,BorderLayout.NORTH);

this.add(scroll,BorderLayout.CENTER);

}

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

}

}


package talk_mouse;

public class Test {

public static void main(String[]args) {

LoginJFrame log=new LoginJFrame();

log.setVisible(true);

}

}

你可能感兴趣的:(大工程之1,这个要真的练习20遍!)