关于java swing编程的问题
哪位高手能告诉下面那个我写的程序到底有什么问题啊,为什么不能显示出界面来啊importjava.net.*;importjava.awt.*;importjava.awt...
哪位高手能告诉下面那个我写的程序到底有什么问题啊,为什么不能显示出界面来啊
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class Client_graph extends JFrame implements ActionListener
{
JLabel LeaveMessage = new JLabel("留言",JLabel.CENTER);
JLabel MySay = new JLabel("我说:");
JButton ClearScreen = new JButton("清屏");
JButton SaveMessage = new JButton("保存");
JButton Retreat = new JButton("退出");
JButton SendMessage = new JButton("发送");
JTextField Message = new JTextField(20);
JTextArea ShowMessage = new JTextArea(40,40);
JPanel Panel1,Panel2,Panel3;
JScrollPane Panel4;
public Client_graph()
{
super("用户窗口");
Panel3.setLayout(new BorderLayout());
Panel3.add(ClearScreen,BorderLayout.NORTH);
Panel3.add(SaveMessage,BorderLayout.CENTER);
Panel3.add(Retreat,BorderLayout.SOUTH);
Panel4 = new JScrollPane(ShowMessage);
Panel1.setLayout(new FlowLayout());
Panel1.add(Panel4);
Panel1.add(Panel3);
Panel2.setLayout(new FlowLayout());
Panel2.add(MySay);
Panel2.add(Message);
Panel2.add(SendMessage);
setLayout(new BorderLayout());
add(LeaveMessage,BorderLayout.NORTH);
add(Panel1,BorderLayout.CENTER);
add(Panel2,BorderLayout.SOUTH);
setSize(600,800);
setLocation(550,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
}
}
public class For_Client
{
public static void main(String args[])
{
new Client_graph();
}
} 展开
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class Client_graph extends JFrame implements ActionListener
{
JLabel LeaveMessage = new JLabel("留言",JLabel.CENTER);
JLabel MySay = new JLabel("我说:");
JButton ClearScreen = new JButton("清屏");
JButton SaveMessage = new JButton("保存");
JButton Retreat = new JButton("退出");
JButton SendMessage = new JButton("发送");
JTextField Message = new JTextField(20);
JTextArea ShowMessage = new JTextArea(40,40);
JPanel Panel1,Panel2,Panel3;
JScrollPane Panel4;
public Client_graph()
{
super("用户窗口");
Panel3.setLayout(new BorderLayout());
Panel3.add(ClearScreen,BorderLayout.NORTH);
Panel3.add(SaveMessage,BorderLayout.CENTER);
Panel3.add(Retreat,BorderLayout.SOUTH);
Panel4 = new JScrollPane(ShowMessage);
Panel1.setLayout(new FlowLayout());
Panel1.add(Panel4);
Panel1.add(Panel3);
Panel2.setLayout(new FlowLayout());
Panel2.add(MySay);
Panel2.add(Message);
Panel2.add(SendMessage);
setLayout(new BorderLayout());
add(LeaveMessage,BorderLayout.NORTH);
add(Panel1,BorderLayout.CENTER);
add(Panel2,BorderLayout.SOUTH);
setSize(600,800);
setLocation(550,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
}
}
public class For_Client
{
public static void main(String args[])
{
new Client_graph();
}
} 展开
2个回答
展开全部
程序有异常啊
Panel1 = new JPanel();
Panel2 = new JPanel();
Panel3 = new JPanel();
这几个面板没有创建对象就使用了,先创建对象 加载构造方法里面就行
还有创建JFrame 对象需要加上 窗口关闭处理,否则即使窗口关闭了,后台进程也是在运行着,占用着资源 构造方法里面加上这个个
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
即:构造方法如下:
public Client_graph()
{
super("用户窗口");
Panel1 = new JPanel();
Panel2 = new JPanel();
Panel3 = new JPanel();
Panel3.setLayout(new BorderLayout());
Panel3.add(ClearScreen,BorderLayout.NORTH);
Panel3.add(SaveMessage,BorderLayout.CENTER);
Panel3.add(Retreat,BorderLayout.SOUTH);
Panel4 = new JScrollPane(ShowMessage);
Panel1.setLayout(new FlowLayout());
Panel1.add(Panel4);
Panel1.add(Panel3);
Panel2.setLayout(new FlowLayout());
Panel2.add(MySay);
Panel2.add(Message);
Panel2.add(SendMessage);
setLayout(new BorderLayout());
add(LeaveMessage,BorderLayout.NORTH);
add(Panel1,BorderLayout.CENTER);
add(Panel2,BorderLayout.SOUTH);
setSize(600,800);
setLocation(550,200);
setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
Panel1 = new JPanel();
Panel2 = new JPanel();
Panel3 = new JPanel();
这几个面板没有创建对象就使用了,先创建对象 加载构造方法里面就行
还有创建JFrame 对象需要加上 窗口关闭处理,否则即使窗口关闭了,后台进程也是在运行着,占用着资源 构造方法里面加上这个个
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
即:构造方法如下:
public Client_graph()
{
super("用户窗口");
Panel1 = new JPanel();
Panel2 = new JPanel();
Panel3 = new JPanel();
Panel3.setLayout(new BorderLayout());
Panel3.add(ClearScreen,BorderLayout.NORTH);
Panel3.add(SaveMessage,BorderLayout.CENTER);
Panel3.add(Retreat,BorderLayout.SOUTH);
Panel4 = new JScrollPane(ShowMessage);
Panel1.setLayout(new FlowLayout());
Panel1.add(Panel4);
Panel1.add(Panel3);
Panel2.setLayout(new FlowLayout());
Panel2.add(MySay);
Panel2.add(Message);
Panel2.add(SendMessage);
setLayout(new BorderLayout());
add(LeaveMessage,BorderLayout.NORTH);
add(Panel1,BorderLayout.CENTER);
add(Panel2,BorderLayout.SOUTH);
setSize(600,800);
setLocation(550,200);
setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询