JButtond用setbounds方法失效
importjava.awt.Graphics;importjava.awt.Image;importjava.awt.event.WindowAdapter;impor...
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class WelcomeFrame extends JFrame{
JButton b1=new JButton("个人信息管理");
JButton b2=new JButton("选课信息管理");
JButton b3=new JButton("奖励信息管理");
JButton b4=new JButton("职务信息管理");
JButton b5=new JButton("退出系统");
WelcomeFrame(){
setBounds(200, 80, 800, 600);
setLayout(null);
setContentPane(new JPanel() {
Image ima = this.getToolkit().getImage("student.jpg");
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(ima, 0, 0, 800, 600, this);
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
JOptionPane.showMessageDialog(null, "感谢您的使用!");
dispose();
System.exit(0);
}
});
b1.setBounds(40,400,80,40);
b2.setBounds(70, 400, 80, 40);
b3.setBounds(100, 400, 80, 40);
b4.setBounds(130, 400,80, 40);
add(b1);
add(b2);
add(b3);
add(b4);
setVisible(true);
}
}
实现下变成都在顶端了 是为什么啊 和我设置的不同啊 展开
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class WelcomeFrame extends JFrame{
JButton b1=new JButton("个人信息管理");
JButton b2=new JButton("选课信息管理");
JButton b3=new JButton("奖励信息管理");
JButton b4=new JButton("职务信息管理");
JButton b5=new JButton("退出系统");
WelcomeFrame(){
setBounds(200, 80, 800, 600);
setLayout(null);
setContentPane(new JPanel() {
Image ima = this.getToolkit().getImage("student.jpg");
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(ima, 0, 0, 800, 600, this);
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
JOptionPane.showMessageDialog(null, "感谢您的使用!");
dispose();
System.exit(0);
}
});
b1.setBounds(40,400,80,40);
b2.setBounds(70, 400, 80, 40);
b3.setBounds(100, 400, 80, 40);
b4.setBounds(130, 400,80, 40);
add(b1);
add(b2);
add(b3);
add(b4);
setVisible(true);
}
}
实现下变成都在顶端了 是为什么啊 和我设置的不同啊 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询