番茄不是土豆😱 刘__建
关注数: 8 粉丝数: 18 发帖数: 420 关注贴吧数: 24
在线求大神指点,找不到哪里出错了? import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; public class Server extends JFrame { CharacterUtil cUtil=new CharacterUtil(); JLabel jLabel1=new JLabel(); JLabel jLabel2=new JLabel(); JLabel jLabel3=new JLabel(); JTextField jTextField=new JTextField(5); JTextArea jTextArea=new JTextArea(); JButton jButton=new JButton(); JPanel jPanel1=new JPanel(); JPanel jPanel2=new JPanel(); JScrollPane jScrollPane=new JScrollPane(); public void launFrame(){ jPanel1.setBorder(BorderFactory.createTitledBorder("服务器信息")); jPanel2.setBorder(BorderFactory.createTitledBorder("在线用户列表")); jLabel1.setText("服务器状态"); jLabel2.setText("停止"); jLabel2.setForeground(Color.red); jLabel3.setText("端口号"); jButton.setText("启动服务器"); jButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Server.this.execute(); } }); jTextArea.setEditable(false); jPanel1.add(jLabel1); jPanel1.add(jLabel2); jPanel1.add(jLabel3); jPanel1.add(jTextField); jPanel1.add(jButton); jTextArea.setColumns(35); jTextArea.setRows(30); jScrollPane.setViewportView(jTextArea); jPanel2.add(jScrollPane); this.getContentPane().add(jPanel1,BorderLayout.NORTH); this.getContentPane().add(jPanel2,BorderLayout.SOUTH); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); this.pack(); this.setVisible(true); } public void execute(){ String hostport=jTextField.getText(); if(CharacterUtil.isEmpty(hostport)){ JOptionPane.showConfirmDialog(this, "端口号不能为空", "警告", JOptionPane.WARNING_MESSAGE); this.jTextField.requestFocus(); return; } if(!CharacterUtil.isNumber(hostport)){ JOptionPane.showConfirmDialog(this, "端口号必须为数字", "警告", JOptionPane.WARNING_MESSAGE); this.jTextField.requestFocusInWindow(); return; } if(!CharacterUtil.isCorrectPort(hostport)){ JOptionPane.showConfirmDialog(this, "端口号必须在1024和65535之间", "警告", JOptionPane.WARNING_MESSAGE); this.jTextField.requestFocusInWindow(); return; } } public static void main(String[] args) { new Server().launFrame(); } }
1 下一页