【发布时间】:2015-01-05 00:29:00
【问题描述】:
在我的井字游戏中,我画了线条,现在我正在尝试放入按钮。我试图放入的第一个按钮,我试图设置边界,但它没有设置边界。它只是填满了整个屏幕。如何让button 只出现在右上角?
public class Project extends JFrame{
static JButton button = new JButton("");
static JButton button2 = new JButton("");
static JButton button3 = new JButton("");
static JButton button4 = new JButton("");
static JButton button5 = new JButton("");
static JButton button6 = new JButton("");
static JButton button7 = new JButton("");
static JButton button8 = new JButton("");
static JButton button9 = new JButton("");
public Project(){
setSize(1000, 750);
}
public void paint(Graphics g){
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
Line2D line = new Line2D.Float(100, 100, 100, 400);
Line2D line2 = new Line2D.Float(200, 100, 200, 400);
Line2D line3 = new Line2D.Float(0, 200, 300, 200);
Line2D line4 = new Line2D.Float(0, 300, 300, 300);
g2.draw(line);
g2.draw(line2);
g2.draw(line3);
g2.draw(line4);
}
public static void main(String[] args){
Project t = new Project();
t.setVisible(true);
button.setBounds(0, 0, 50, 50);
t.add(button);
}
}
【问题讨论】:
-
为什么不使用
GridLayout?
标签: java swing graphics jframe jbutton