java GUI 显示不出来?frame里没东西?
importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclassRegisterextend...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Register extends JFrame{
public static void main(String[] args) {
JFrame frame = new Register();
frame.setTitle("Register");
frame.setSize(400, 400);
frame.setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
JLabel jl1=new JLabel("name");
JLabel jl2=new JLabel("id");
JLabel jl3=new JLabel("gender");
JLabel jl4=new JLabel("height");
JLabel jl5=new JLabel("weight");
JLabel jl6=new JLabel("position");
JLabel jl7=new JLabel("Log In",SwingConstants.CENTER);
JButton jb1=new JButton("male");
JButton jb2=new JButton("femle");
JButton jb3=new JButton("reset");
JButton jb4=new JButton("go");
JButton jb5=new JButton("back");
JTextField jtf1=new JTextField();
JTextField jtf2=new JTextField();
JTextField jtf3=new JTextField();
JTextField jtf4=new JTextField();
public Register(){
JPanel jp1=new JPanel();
jp1.setLayout(new GridLayout(6,2));
jp1.add(jl1);
jp1.add(jtf1);
jp1.add(jl2);
jp1.add(jtf2);
jp1.add(jl3);
JPanel jp2=new JPanel();
jp2.setLayout(new FlowLayout());
jp2.add(jb1);
jp2.add(jb2);
jp1.add(jp2);
jp1.add(jl4);
jp1.add(jtf3);
jp1.add(jl5);
jp1.add(jtf4);
jp1.add(jl6);
jp1.add(new JComboBox(new String[]{"Beijing","Shanghai","Hangzhou","Nanjing"}));
JPanel jp3=new JPanel();
jp3.add(jb3);
jp3.add(jb4);
jp3.add(jb5);
jp3.setLayout(new FlowLayout());
this.add(jl7,BorderLayout.NORTH);
this.add(jp1,BorderLayout.CENTER);
this.add(jp3,BorderLayout.SOUTH);
jb4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(jtf1.getText().equals("")||jtf2.getText().equals("")||jtf3.getText().equals("")||jtf4.getText().equals("")){
int selection1= JOptionPane.showConfirmDialog(null, "wrong input",null,JOptionPane.YES_NO_CANCEL_OPTION
,JOptionPane.QUESTION_MESSAGE,null);
}else{
int selection2= JOptionPane.showConfirmDialog(null, "Name:"+jtf1.getText()+"\n",null,JOptionPane.YES_NO_CANCEL_OPTION
,JOptionPane.QUESTION_MESSAGE,null);}
}
});
}
} 展开
import java.awt.*;
import java.awt.event.*;
public class Register extends JFrame{
public static void main(String[] args) {
JFrame frame = new Register();
frame.setTitle("Register");
frame.setSize(400, 400);
frame.setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
JLabel jl1=new JLabel("name");
JLabel jl2=new JLabel("id");
JLabel jl3=new JLabel("gender");
JLabel jl4=new JLabel("height");
JLabel jl5=new JLabel("weight");
JLabel jl6=new JLabel("position");
JLabel jl7=new JLabel("Log In",SwingConstants.CENTER);
JButton jb1=new JButton("male");
JButton jb2=new JButton("femle");
JButton jb3=new JButton("reset");
JButton jb4=new JButton("go");
JButton jb5=new JButton("back");
JTextField jtf1=new JTextField();
JTextField jtf2=new JTextField();
JTextField jtf3=new JTextField();
JTextField jtf4=new JTextField();
public Register(){
JPanel jp1=new JPanel();
jp1.setLayout(new GridLayout(6,2));
jp1.add(jl1);
jp1.add(jtf1);
jp1.add(jl2);
jp1.add(jtf2);
jp1.add(jl3);
JPanel jp2=new JPanel();
jp2.setLayout(new FlowLayout());
jp2.add(jb1);
jp2.add(jb2);
jp1.add(jp2);
jp1.add(jl4);
jp1.add(jtf3);
jp1.add(jl5);
jp1.add(jtf4);
jp1.add(jl6);
jp1.add(new JComboBox(new String[]{"Beijing","Shanghai","Hangzhou","Nanjing"}));
JPanel jp3=new JPanel();
jp3.add(jb3);
jp3.add(jb4);
jp3.add(jb5);
jp3.setLayout(new FlowLayout());
this.add(jl7,BorderLayout.NORTH);
this.add(jp1,BorderLayout.CENTER);
this.add(jp3,BorderLayout.SOUTH);
jb4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(jtf1.getText().equals("")||jtf2.getText().equals("")||jtf3.getText().equals("")||jtf4.getText().equals("")){
int selection1= JOptionPane.showConfirmDialog(null, "wrong input",null,JOptionPane.YES_NO_CANCEL_OPTION
,JOptionPane.QUESTION_MESSAGE,null);
}else{
int selection2= JOptionPane.showConfirmDialog(null, "Name:"+jtf1.getText()+"\n",null,JOptionPane.YES_NO_CANCEL_OPTION
,JOptionPane.QUESTION_MESSAGE,null);}
}
});
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询