Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java中如何在方法中添加圆? publicstaticvoidboard(){//Create's my board { JFrame board=新JFrame(); 板。设置尺寸(400200); 棋盘游戏集(“问答棋盘游戏”); 容器窗格=board.getContentPane(); setLayout(新的GridLayout(行、列)); 色温; 对于(int i=0;i_Java_User Interface - Fatal编程技术网

在java中如何在方法中添加圆? publicstaticvoidboard(){//Create's my board { JFrame board=新JFrame(); 板。设置尺寸(400200); 棋盘游戏集(“问答棋盘游戏”); 容器窗格=board.getContentPane(); setLayout(新的GridLayout(行、列)); 色温; 对于(int i=0;i

在java中如何在方法中添加圆? publicstaticvoidboard(){//Create's my board { JFrame board=新JFrame(); 板。设置尺寸(400200); 棋盘游戏集(“问答棋盘游戏”); 容器窗格=board.getContentPane(); setLayout(新的GridLayout(行、列)); 色温; 对于(int i=0;i,java,user-interface,Java,User Interface,我用java编写了这段代码,我想知道如何添加两个圆圈,这样就可以创建一个包含两块的电路板?谢谢 p.S我是java新手重写paintComponent(Graphics g)方法 希望这有帮助 public static void board(){ //Create's my board { JFrame board = new JFrame(); board.setSize(400, 200 ); board.setTitle("Quiz

我用java编写了这段代码,我想知道如何添加两个圆圈,这样就可以创建一个包含两块的电路板?谢谢


p.S我是java新手

重写paintComponent(Graphics g)方法

希望这有帮助

public static void board(){ //Create's my board
    {
        JFrame board = new JFrame();
        board.setSize(400, 200 );
        board.setTitle("Quiz Board Game");
        Container pane = board.getContentPane();
        pane.setLayout(new GridLayout(rows, columns));
        Color temp;
        for (int i = 0; i < rows; i++)
        {
            if (i%2 == 0)
            {
                temp = col1;
            }
            else
            {
                temp = col2;
            }
            for (int j = 0; j < columns; j++)
            {
                JPanel panel = new JPanel();
                panel.setBackground(temp);
                if (temp.equals(col1))
                {
                    temp = col2;
                }
                else
                {
                    temp = col1;
                }
                pane.add(panel);
            }
        }
        board.setVisible(true);
// create Image 
Image i = new ImageIcon("//filepath").getImage();
int pointXForFirstPiece = 0; // update for the x position of where your piece will be
int pointYForFirstPiece = 0; // update for the y position

public void paintComponent(Graphics g) {
    // do the painting for the two objects here
    // paint image
    // create another image object as done above, and then 
    // rewrite the line below for the second piece
    g.drawImage(i, pointXForFirstPiece, pointYForFirstPiece, null);
}