跪求修改java代码
答案:2 悬赏:80 手机版
解决时间 2021-01-23 00:11
- 提问者网友:最爱你的唇
- 2021-01-22 06:22
跪求修改java代码
最佳答案
- 五星知识达人网友:往事埋风中
- 2021-01-22 06:34
最偷懒的话 使用 setBounds 不就行了?
button1.setBounds(50, 50,button1 getWidth(), button1.getHeight());
button2.setBounds(250, 50,button2 getWidth(), button2.getHeight());
button3.setBounds(50, 150,button3 getWidth(), button3.getHeight());
button4.setBounds(250, 150,button4 getWidth(), button4.getHeight());
button5.setBounds(50, 250,button5 getWidth(), button5.getHeight());
button6.setBounds(250, 250,button6 getWidth(), button6.getHeight());
button1.setBounds(50, 50,button1 getWidth(), button1.getHeight());
button2.setBounds(250, 50,button2 getWidth(), button2.getHeight());
button3.setBounds(50, 150,button3 getWidth(), button3.getHeight());
button4.setBounds(250, 150,button4 getWidth(), button4.getHeight());
button5.setBounds(50, 250,button5 getWidth(), button5.getHeight());
button6.setBounds(250, 250,button6 getWidth(), button6.getHeight());
全部回答
- 1楼网友:你可爱的野爹
- 2021-01-22 08:01
这个box 还没用过呢 看见了 借葫芦画瓢 改一下
public class chuangkou extends JFrame implements ActionListener {
public static void main(String[] args) {
chuangkou c = new chuangkou();
}
JFrame frame = new JFrame("选择窗口");
JPanel imagePanel;
Button button1, button2, button3, button4, button5, button6;
Box box;
Box box1;
Box box2;
Box box3;
Label label;
Panel p1;
chuangkou() {
Toolkit kit = Toolkit.getDefaultToolkit();
p1 = new Panel();
label = new Label("欢迎使用成绩管理系统", Label.CENTER);
label.setFont(new Font("隶书", Font.BOLD, 30));
p1.add(label);
button1 = new Button("添加");
button2 = new Button("删除");
button3 = new Button("修改");
button4 = new Button("查询");
button5 = new Button("返回");
button6 = new Button("退出");
// box = Box.createHorizontalBox();
box = Box.createVerticalBox();//从上到下
box1 = Box.createHorizontalBox();
box2 = Box.createHorizontalBox();
box3 = Box.createHorizontalBox();
box1.add(button1);
box1.add(Box.createHorizontalStrut(8));
box1.add(button2);
box1.add(Box.createHorizontalStrut(8));
box2.add(button3);
box2.add(Box.createHorizontalStrut(8));
box2.add(button4);
box2.add(Box.createHorizontalStrut(8));
box3.add(button5);
box3.add(Box.createHorizontalStrut(8));
box3.add(button6);
box.add(box1);
box.add(Box.createHorizontalStrut(8));
box.add(box2);
box.add(Box.createHorizontalStrut(8));
box.add(box3);
box.add(Box.createHorizontalStrut(8));
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
button6.addActionListener(this);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(new FlowLayout());
imagePanel.add(p1, BorderLayout.NORTH);
imagePanel.add(box, BorderLayout.CENTER);
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置关闭后状态
frame.setBounds(200, 200, 500, 300);
frame.setResizable(false);// 设置窗口大小不可改变
frame.setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button6) {
System.exit(0);
}
if (e.getSource() == button1) {
// new charu();
}
if (e.getSource() == button2) {
// new shanchu();
}
if (e.getSource() == button3) {
// new xiugai();
}
if (e.getSource() == button4) {
// new chaxun();
}
if (e.getSource() == button5) {
// new denglu();
frame.dispose();
} else {
}
}
}
public class chuangkou extends JFrame implements ActionListener {
public static void main(String[] args) {
chuangkou c = new chuangkou();
}
JFrame frame = new JFrame("选择窗口");
JPanel imagePanel;
Button button1, button2, button3, button4, button5, button6;
Box box;
Box box1;
Box box2;
Box box3;
Label label;
Panel p1;
chuangkou() {
Toolkit kit = Toolkit.getDefaultToolkit();
p1 = new Panel();
label = new Label("欢迎使用成绩管理系统", Label.CENTER);
label.setFont(new Font("隶书", Font.BOLD, 30));
p1.add(label);
button1 = new Button("添加");
button2 = new Button("删除");
button3 = new Button("修改");
button4 = new Button("查询");
button5 = new Button("返回");
button6 = new Button("退出");
// box = Box.createHorizontalBox();
box = Box.createVerticalBox();//从上到下
box1 = Box.createHorizontalBox();
box2 = Box.createHorizontalBox();
box3 = Box.createHorizontalBox();
box1.add(button1);
box1.add(Box.createHorizontalStrut(8));
box1.add(button2);
box1.add(Box.createHorizontalStrut(8));
box2.add(button3);
box2.add(Box.createHorizontalStrut(8));
box2.add(button4);
box2.add(Box.createHorizontalStrut(8));
box3.add(button5);
box3.add(Box.createHorizontalStrut(8));
box3.add(button6);
box.add(box1);
box.add(Box.createHorizontalStrut(8));
box.add(box2);
box.add(Box.createHorizontalStrut(8));
box.add(box3);
box.add(Box.createHorizontalStrut(8));
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
button6.addActionListener(this);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(new FlowLayout());
imagePanel.add(p1, BorderLayout.NORTH);
imagePanel.add(box, BorderLayout.CENTER);
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置关闭后状态
frame.setBounds(200, 200, 500, 300);
frame.setResizable(false);// 设置窗口大小不可改变
frame.setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button6) {
System.exit(0);
}
if (e.getSource() == button1) {
// new charu();
}
if (e.getSource() == button2) {
// new shanchu();
}
if (e.getSource() == button3) {
// new xiugai();
}
if (e.getSource() == button4) {
// new chaxun();
}
if (e.getSource() == button5) {
// new denglu();
frame.dispose();
} else {
}
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯