日期:2014-05-20  浏览次数:20765 次

请高手帮忙看一段代码
问题都写在注释里了,请参考注释


import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;


public class WindowDemo extends javax.swing.JFrame {
private JPanel jPanel1;
private JLabel username;
private JPasswordField passText;
private JDialog jDialog1;
private JButton submit;
private JLabel password;
private JTextField userText;

/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
WindowDemo inst = new WindowDemo();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}

public WindowDemo() {
super();
initGUI();
}

private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
{
jPanel1 = new JPanel();
jPanel1.setLayout(null);
getContentPane().add(jPanel1);
jPanel1.setBounds(0, 0, 392, 266);
{
username = new JLabel();
jPanel1.add(username);
username.setText("\u8d26\u53f7:");
username.setBounds(73, 53, 32, 15);
}
{
userText = new JTextField(83);
jPanel1.add(userText);
userText.setBounds(123, 50, 175, 22);
}
{
password = new JLabel();
jPanel1.add(password);
password.setText("\u5bc6\u7801:");
password.setBounds(73, 102, 30, 15);
}
{
passText = new JPasswordField();
jPanel1.add(passText);
passText.setBounds(121, 99, 177, 22);
}
{
submit = new JButton();
jPanel1.add(submit);
submit.setText("\u767b\u5f55");
submit.setBounds(150, 176, 83, 22);
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
System.out.println("准备实体化方法");
new socketsendss();//代码运行到这一步就不能运行了,也就是不能实例化这个类,如果单独运行这个类,是正常的
}
});
}
}
pack();
setSize(400, 300);
} catch (Exception e) {
throw new RuntimeException("发生错误啦");
}
}
}


class Dialogs{
private JDialog dia;
private String info;
private String title;
private JLabel latxt;
private JButton bt;
Dialogs(String info,String title){
this.info=info;
this.title=title;
}

public void showDialog(){
dia =new JDialog();
dia.setBounds(300, 300, 200, 100);
dia.setTitle(this.title);
dia.setLayout(null);

latxt=new JLabel();
latxt.setText(this.info);
latxt.setBounds(50, 0, 100, 30);

bt=new JButton();
bt.setText("确定");
bt.setBounds(50, 30, 80, 30);


dia.add(latxt);
dia.add(bt);
dia.setVisible(true);
{
bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {