帮忙看下代码package com;
import java.awt.*;
import java.awt.event.*;import javax.swing.*;
public class Client{
JFrame frame = new JFrame("聊天室");
private JPanel landing = new JPanel();
private JPanel chatpanel = new JPanel();
private JTextArea content = new JTextArea();
private JTextArea edit = new JTextArea();
JButton loading = new JButton("登陆");
public JTextField info = new JTextField(20);
public Client(){
frame.setSize(400,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
private void load(){
landing.add(new JLabel("请输入你的姓名"));
landing.add(info);
landing.add(loading);
frame.add(landing,BorderLayout.CENTER);
//作用是想点击“登陆”按钮后把之前那个landing面板给删了。然后显示为content面板中的内容
loading.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
frame.remove(landing);
content.add(content, BorderLayout.NORTH);
content.add(edit,BorderLayout.SOUTH);
frame.add(content);
}
});
}
public static void main(String[] args) {
Client xinming = new Client();
xinming.load();
}
}
但是当程序运行时点击“登陆”按钮,并不能把面板给换了。而且程序卡死。求帮忙解释下。。
import java.awt.*;
import java.awt.event.*;import javax.swing.*;
public class Client{
JFrame frame = new JFrame("聊天室");
private JPanel landing = new JPanel();
private JPanel chatpanel = new JPanel();
private JTextArea content = new JTextArea();
private JTextArea edit = new JTextArea();
JButton loading = new JButton("登陆");
public JTextField info = new JTextField(20);
public Client(){
frame.setSize(400,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
private void load(){
landing.add(new JLabel("请输入你的姓名"));
landing.add(info);
landing.add(loading);
frame.add(landing,BorderLayout.CENTER);
//作用是想点击“登陆”按钮后把之前那个landing面板给删了。然后显示为content面板中的内容
loading.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
frame.remove(landing);
content.add(content, BorderLayout.NORTH);
content.add(edit,BorderLayout.SOUTH);
frame.add(content);
}
});
}
public static void main(String[] args) {
Client xinming = new Client();
xinming.load();
}
}
但是当程序运行时点击“登陆”按钮,并不能把面板给换了。而且程序卡死。求帮忙解释下。。
解决方案 »
- 用JUnit总是报错,找不到什么问题,求助前辈
- 求高手指点迷津,我想学Java从哪里开始着手!
- 救命啊!!!
- 计算器功能键的弧度和角度转换如何设计
- IO操作,选取html里面的显示内容
- webservice版没人答.求webservice的客户端程序写法.
- BASE64Encoder竟然编出回车换行了?怎么回事?
- 请问如何使javac 在任何目录下都能用?
- 安装tomcat4的问题
- jframe和frame的repaint方法的不同
- String怎么转long
- 我是新手 求解Exception in thread "main" java.lang.NoSuchMethodError: main
import java.awt.event.*;
import javax.swing.*;public class Client {
JFrame frame = new JFrame("聊天室");
private JPanel landing = new JPanel();
private JPanel chatpanel = new JPanel();
private JTextArea content = new JTextArea();
private JTextArea edit = new JTextArea();
JButton loading = new JButton("登陆");
public JTextField info = new JTextField(20); public Client() {
load();
frame.setSize(400, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
private void load() {
landing.add(new JLabel("请输入你的姓名"));
landing.add(info);
landing.add(loading);
frame.add(landing, BorderLayout.NORTH);
chatpanel.setLayout(new BorderLayout());
chatpanel.add(content, BorderLayout.NORTH);
chatpanel.add(edit, BorderLayout.SOUTH);
// 作用是想点击“登陆”按钮后把之前那个landing面板给删了。然后显示为content面板中的内容
loading.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
loading.setEnabled(false);
landing.setVisible(false);
frame.add(chatpanel,BorderLayout.CENTER);
frame.validate();
}
});
} public static void main(String[] args) {
Client xinming = new Client();
}
}