一个简单的JAVA GUI程序都欺负我 大家来给我看看

来源:百度知道 编辑:UC知道 时间:2024/06/21 16:50:01
运行出来就的GUI有问题 不信你自己试试
中间那个框是空的 哦 不是 是漏的!~~ 怎么回事?
它警等告说我用了过时的API 怎么回事?
import javax.swing.*;
import java.awt.*;
public class Login extends JFrame{
private JButton login=new JButton("登陆");
private JButton cancel=new JButton("取消");
private JPanel panelsouth=new JPanel();
public Login(String title){
super(title);
this.setBounds(300,300,350,250);
layout();
this.setVisible(true);
}
public void layout(){
panelsouth.add(login);
panelsouth.add(cancel);
this.getContentPane().add(login,BorderLayout.SOUTH);
}
public static void main(String ary[]){
new Login("home financial management system");
}
}

方法名称layout是父类方法,你把父类重写了,把方法名变更一下就好了。例如下面代码:
package org.ace.test;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class Login extends JFrame {
private JButton login = new JButton("登陆");

private JButton cancel = new JButton("取消");

private JPanel panelsouth = new JPanel();

public Login(String title) {
super(title);
this.setBounds(300, 300, 350, 250);
layout1();
this.setVisible(true);
}

public void layout1() {
panelsouth.add(login);
panelsouth.add(cancel);
this.getContentPane().add(login, BorderLayout.SOUTH);
}

public static void main(String ary[]) {
new Login("home financial management system");
}
}