这个JAVA的界面程序哪里错了?

来源:百度知道 编辑:UC知道 时间:2024/06/09 16:13:13
import javax.swing.*;
import java.awt.*;
public class Sample {
static JFrame f1;
static JPanel p1;
JLabel lbla1;
JTextField txta1;
JLabel lblb1;
JTextField b1;
JButton c1;
JButton c2;

public Sample() {

JButton c1=new JButton("登录");
JButton c2=new JButton("取消");
JLabel lbla1=new JLabel("用户");
JTextField txtb1=new JTextField();
JLabel lblb1=new JLabel("密码");
JTextField b1=new JTextField();

p1=new JPanel();
c1=new JButton("登录");
c2=new JButton("取消");
p1.add(c1);
c1.setLabel("登录");
p1.add(c2);
c2.setLabel("取消");

}
public static void main (String[] args) {
f1=new JFrame("登录界面");
f1.getContentPane().add(p1);
f1.setSize(300,300);<

在你程序中的c1.setLabel("登录"); 和c2.setLabel("取消"); 所用调用的方法已经过时了,所以出现这种提示。
帮你改了一下:因为时间有限,不足之处楼主再添加以下,比较容易的。
import javax.swing.*;

public class Sample extends JFrame{

JLabel lbla1;
JTextField txta1;
JLabel lblb1;
JTextField b1;
JButton c1;
JButton c2;

public Sample(String title) {
super(title) ;
JButton c1=new JButton("登录");
JButton c2=new JButton("取消");
JLabel lbla1=new JLabel("用户");
JTextField txtb1=new JTextField();
JLabel lblb1=new JLabel("密码");
JTextField b1=new JTextField();

JPanel p1=new JPanel();
c1=new JButton("登录");
c2=new JButton("取消");
p1.add(c1);
c1.setText("登录");
p1.add(c2);
c2.setText("取消");

this.getContentPane().add(p1);
this.setSize(300,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON