小编Phi*_*ess的帖子

JAVA GUI代码未按预期运行

我从书中输入了这段代码

public class SimpleGui3C  {

JFrame frame;


public static void main (String[] args) {
   SimpleGui3C gui = new SimpleGui3C();
   gui.go();
}

public void go() {
   frame = new JFrame("My own code");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


   MyDrawPanel drawPanel = new MyDrawPanel();

   frame.getContentPane().add(BorderLayout.CENTER, drawPanel);

   frame.setSize(420,300);
   frame.setVisible(true);
}}

class MyDrawPanel extends JPanel {

public void painComponent(Graphics g) {

    g.fillRect(0,0,this.getWidth(), this.getHeight());


    int red = (int) (Math.random() * 255);
    int green = (int) (Math.random() * 255);
    int blue = (int) (Math.random() * 255);

    Color randomColor = new Color(red, …
Run Code Online (Sandbox Code Playgroud)

java user-interface

1
推荐指数
1
解决办法
41
查看次数

标签 统计

java ×1

user-interface ×1