java图形化界面 做如图的题!
1个回答
展开全部
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class SwingDemo extends JFrame
{
private JButton button1;
private JButton button2;
private JButton button3;
private JButton button4;
private JPanel north;
public SwingDemo(){
this.setLayout(new BorderLayout());
button1 = new JButton("1");
Dimension preferredSize = new Dimension(140, 30);
button1.setPreferredSize(preferredSize );
button2 = new JButton("2");
button2.setPreferredSize(preferredSize);
button3 = new JButton("3");
button4 = new JButton("4");
north = new JPanel();
north.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 1));
north.add(button1);
north.add(button2);
this.add(north, BorderLayout.NORTH);
this.add(button3, BorderLayout.CENTER);
this.add(button4, BorderLayout.SOUTH);
this.setBounds(100, 100, 300, 300);
this.setVisible(true);
}
public static void main(String[] args){
SwingDemo sd = new SwingDemo();
}
}
手工编写的请采纳
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class SwingDemo extends JFrame
{
private JButton button1;
private JButton button2;
private JButton button3;
private JButton button4;
private JPanel north;
public SwingDemo(){
this.setLayout(new BorderLayout());
button1 = new JButton("1");
Dimension preferredSize = new Dimension(140, 30);
button1.setPreferredSize(preferredSize );
button2 = new JButton("2");
button2.setPreferredSize(preferredSize);
button3 = new JButton("3");
button4 = new JButton("4");
north = new JPanel();
north.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 1));
north.add(button1);
north.add(button2);
this.add(north, BorderLayout.NORTH);
this.add(button3, BorderLayout.CENTER);
this.add(button4, BorderLayout.SOUTH);
this.setBounds(100, 100, 300, 300);
this.setVisible(true);
}
public static void main(String[] args){
SwingDemo sd = new SwingDemo();
}
}
手工编写的请采纳
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询