BUTTON和几个JTextField不显示,当鼠标放上去后显示。最小化在重新最大化后显示正常,怎么回事呀,源代码如下:publicclassCustomFrame{privateJFrameframe;publicJTextAreainformati...
BUTTON和几个JTextField不显示,当鼠标放上去后显示。最小化在重新最大化后显示正常,怎么回事呀,源代码如下:
public class CustomFrame {
private JFrame frame;
public JTextArea information;
private JTextArea sendMessage;
private JTextField ip;
private JTextField port;
private JButton attach;
private Custom custom;
private CustomFrame cf=this;
CustomFrame()
{
go();
}
public void go()
{
frame=new JFrame("客户端 ***********杨鹏伟**1937213**计科72");
frame.setBounds(700,200,500,500);
frame.setResizable(false);//不能最大化
frame.setVisible(true);
{
JLabel lb=new JLabel("Port:");
lb.setBounds(230,15,50,25);
frame.getContentPane().add(lb);
}
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 50, 480, 200);
frame.getContentPane().add(scrollPane);
information=new JTextArea();
scrollPane.add(information);
information.setEditable(false);
scrollPane.setViewportView(information);
JScrollPane scrollPane2 = new JScrollPane();
scrollPane2.setBounds(10, 300, 480, 100);
frame.getContentPane().add(scrollPane2);
sendMessage = new JTextArea();
scrollPane2.setViewportView(sendMessage);
ip = new JTextField();
ip.setBounds(70, 15, 150, 25);
ip.setText("127.0.0.1");
frame.getContentPane().add(ip);
port=new JTextField();
port.setBounds(280, 15, 100, 25);
port.setText("9999");
frame.getContentPane().add(port);
attach=new JButton("连接");
attach.setBounds(400,10,80,35);
frame.getContentPane().add(attach);
attach.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
String ipValue=ip.getText();
String portValue=port.getText();
if(ipValue==null||ipValue.length()<=0)
JOptionPane.showMessageDialog(frame, "请输入服务器IP地址!");
else if(!ipValue.matches("[0-9.]+"))
JOptionPane.showMessageDialog(frame, "IP地址应为0-9数字和.组成");
else if(portValue==null||portValue.length()<=0)
JOptionPane.showMessageDialog(frame, "请输入端口号");
else if(!portValue.matches("[0-9]+"))
JOptionPane.showMessageDialog(frame, "端口应为0-65535的数字!");
else if(Integer.parseInt(portValue)<0||Integer.parseInt(portValue)>65535)
JOptionPane.showMessageDialog(frame, "端口应为0-65535之间的数值");
else {
ip.setEditable(false);
port.setEditable(false);
custom=new Custom(ipValue,Integer.parseInt(portValue),cf);
custom.start();
attach.setEnabled(true);
}
}
});
JButton send=new JButton("发送");
send.setBounds(400, 400,80, 50);
frame.getContentPane().add(send);
展开