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(); } }}
下一篇:python代码