java窗口建立了两个按钮为什么前面的按钮会被后面的覆盖 - 爱问答

(爱问答)

java窗口建立了两个按钮为什么前面的按钮会被后面的覆盖

这是原代码,这个窗口设计的是由初界面点击进入的第二个界面,但是为什么创立的两个按钮只显示后建立的那一个,而且整个窗口都被这一个按钮占满,拉动窗口大小也是如此。
package 测试;
 
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
public class Newframe extends JFrame 
{
private JButton button1;
private JButton button2;
public Newframe()
    {
        this.setSize(300,200);
        this.setLocation(300,400);
        this.setVisible(true);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
 
        button1 = new JButton("返回");
        button1 = new JButton("测试");
        add(button1);
        add(button2);
        button1.setBounds(30,20,300,400);
        button2.setBounds(80,20,30,40);
 
    }
public void actionPerformed(ActionEvent e) 
    {
        if(e.getSource() == button1)
        {
            this.dispose();
            new Menu();
        }
    }
}

相关标签:java

下一篇:python代码

上一篇:这个配置能打cfLOL还需不需要完善

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?