Java 程序代码没有提示错误,但是无法显示运行结果
importjavax.swing.*;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swi...
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class User extends JFrame {
public JPanel useJPanel;
public JButton btn1;
public JButton btn2;
public JTextField text1;
public JPasswordField pdwField;
public JLabel userlog;
public JLabel username;
public JLabel userpdw;
public void Userlog(){
useJPanel =new JPanel();
userlog = new JLabel("用户登录");
username = new JLabel("用户名:");
userpdw = new JLabel("密 码:");
text1 =new JTextField();
pdwField = new JPasswordField();
btn1 =new JButton("登录");
btn2 =new JButton("取消");
usermain();
}
public void usermain(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setSize(300,200);
this.useJPanel.setLayout(null);
this.userlog.setBounds(120,15,60,20);
this.username.setBounds(50,55,60,20);
this.userpdw.setBounds(50,85,60,25);
this.text1.setBounds(110,55,120,20);
this.pdwField.setBounds(110,85,120,20);
this.btn1.setBounds(85,120,60,20);
this.btn2.setBounds(155,120,60,20);
this.useJPanel.add(userlog);
this.useJPanel.add(username);
this.useJPanel.add(userpdw);
this.useJPanel.add(text1);
this.useJPanel.add(pdwField);
this.useJPanel.add(btn1);
this.useJPanel.add(btn2);
this.add(useJPanel);
this.setVisible(true);
}
public static void main(String []args){
new User();
}
}
知道问题所在了……看看各位能不能细心点喽!嘿嘿,回答出来就给分!不是故意卖弄的 ,这分不能不给,但是我挣分也不容易的哦 展开
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class User extends JFrame {
public JPanel useJPanel;
public JButton btn1;
public JButton btn2;
public JTextField text1;
public JPasswordField pdwField;
public JLabel userlog;
public JLabel username;
public JLabel userpdw;
public void Userlog(){
useJPanel =new JPanel();
userlog = new JLabel("用户登录");
username = new JLabel("用户名:");
userpdw = new JLabel("密 码:");
text1 =new JTextField();
pdwField = new JPasswordField();
btn1 =new JButton("登录");
btn2 =new JButton("取消");
usermain();
}
public void usermain(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setSize(300,200);
this.useJPanel.setLayout(null);
this.userlog.setBounds(120,15,60,20);
this.username.setBounds(50,55,60,20);
this.userpdw.setBounds(50,85,60,25);
this.text1.setBounds(110,55,120,20);
this.pdwField.setBounds(110,85,120,20);
this.btn1.setBounds(85,120,60,20);
this.btn2.setBounds(155,120,60,20);
this.useJPanel.add(userlog);
this.useJPanel.add(username);
this.useJPanel.add(userpdw);
this.useJPanel.add(text1);
this.useJPanel.add(pdwField);
this.useJPanel.add(btn1);
this.useJPanel.add(btn2);
this.add(useJPanel);
this.setVisible(true);
}
public static void main(String []args){
new User();
}
}
知道问题所在了……看看各位能不能细心点喽!嘿嘿,回答出来就给分!不是故意卖弄的 ,这分不能不给,但是我挣分也不容易的哦 展开
4个回答
展开全部
public static void main(String []args){
User u = new User();
u.Userlog(); //调用方法
}
你光声明对象不调用方法哪有显示结果
User u = new User();
u.Userlog(); //调用方法
}
你光声明对象不调用方法哪有显示结果
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你这个Userlog()方法都没调用,当然没东西了,
改
new User().userlog();
改
new User().userlog();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
因为你只是创建了一个User对象啊
new User();
改成
User user=new User();
user.Userlog();
应该就可以了
new User();
改成
User user=new User();
user.Userlog();
应该就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询