[急]求救,关于JAVA弹出对话框的问题,请大神看一下我的代码哪里出错了
publicclassTestMyftpextendsJFrame{privateJLabelname_IpAddress=newJLabel("FTP服务器端IP地址:...
public class TestMyftp extends JFrame
{
private JLabel name_IpAddress = new JLabel("FTP服务器端IP地址:");
private JTextField jt_IpAddress = new JTextField();
private JButton jb__login = new JButton("登入");
private JLabel jl_info = new JLabel("");
private JLabel jl_name = new JLabel("用户名");
private JTextField jtf_name = new JTextField();
private JLabel jl_psw = new JLabel("密码");
private JTextField jtf_psw = new JTextField();
private JButton jb_login = new JButton("登录");
private JButton jb_exit = new JButton("退出");
String name = null;
String password = null;
FTPClient ftpClient = new FTPClient();
String IPAddress = null;
public TestMyftp()
{
this.setTitle("选择服务器IP");
this.setLayout(null);
name_IpAddress.setBounds(40,20,200, 26);
jt_IpAddress.setBounds(40,50,95,30);
jb__login.setBounds(150,50,60,30);
this.add(name_IpAddress);
this.add(jt_IpAddress);
this.add(jb__login);
this.setBounds(50, 50, 250, 150);
jb__login.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
login();
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void login()
{
IPAddress = jt_IpAddress.getText();
try
{
ftpClient.connect(IPAddress);
dispose();
JOptionPane.showMessageDialog(null, "连接成功");
init();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "连接出错,请检查IP地址");
}
}
public void init()
{
JFrame Login = new JFrame();
Login.setTitle("登陆界面");
Login.setLayout(null);
jl_info.setBounds(10, 10, 200, 26);
jl_name.setBounds(10, 50, 50, 30);
jtf_name.setBounds(60, 50, 120, 26);
jl_psw.setBounds(10, 100, 50, 30);
jtf_psw.setBounds(60, 100, 120, 26);
jb_login.setBounds(20, 140, 80, 30);
jb_exit.setBounds(120, 140, 80, 30);
Login.add(jl_info);
Login.add(jl_name);
Login.add(jtf_name);
Login.add(jl_psw);
Login.add(jtf_psw);
Login.add(jb_login);
Login.add(jb_exit);
Login.setBounds(50, 100, 220, 220);
jb_login.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
login2();
}
});
jb_exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void login2()
{
}
public static void main(String[] args)
{
new TestMyftp();
}
} 展开
{
private JLabel name_IpAddress = new JLabel("FTP服务器端IP地址:");
private JTextField jt_IpAddress = new JTextField();
private JButton jb__login = new JButton("登入");
private JLabel jl_info = new JLabel("");
private JLabel jl_name = new JLabel("用户名");
private JTextField jtf_name = new JTextField();
private JLabel jl_psw = new JLabel("密码");
private JTextField jtf_psw = new JTextField();
private JButton jb_login = new JButton("登录");
private JButton jb_exit = new JButton("退出");
String name = null;
String password = null;
FTPClient ftpClient = new FTPClient();
String IPAddress = null;
public TestMyftp()
{
this.setTitle("选择服务器IP");
this.setLayout(null);
name_IpAddress.setBounds(40,20,200, 26);
jt_IpAddress.setBounds(40,50,95,30);
jb__login.setBounds(150,50,60,30);
this.add(name_IpAddress);
this.add(jt_IpAddress);
this.add(jb__login);
this.setBounds(50, 50, 250, 150);
jb__login.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
login();
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void login()
{
IPAddress = jt_IpAddress.getText();
try
{
ftpClient.connect(IPAddress);
dispose();
JOptionPane.showMessageDialog(null, "连接成功");
init();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "连接出错,请检查IP地址");
}
}
public void init()
{
JFrame Login = new JFrame();
Login.setTitle("登陆界面");
Login.setLayout(null);
jl_info.setBounds(10, 10, 200, 26);
jl_name.setBounds(10, 50, 50, 30);
jtf_name.setBounds(60, 50, 120, 26);
jl_psw.setBounds(10, 100, 50, 30);
jtf_psw.setBounds(60, 100, 120, 26);
jb_login.setBounds(20, 140, 80, 30);
jb_exit.setBounds(120, 140, 80, 30);
Login.add(jl_info);
Login.add(jl_name);
Login.add(jtf_name);
Login.add(jl_psw);
Login.add(jtf_psw);
Login.add(jb_login);
Login.add(jb_exit);
Login.setBounds(50, 100, 220, 220);
jb_login.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
login2();
}
});
jb_exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void login2()
{
}
public static void main(String[] args)
{
new TestMyftp();
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询