Home > Back-end >  Always resolve a symbol frame, why I frame is the idea of standard red?
Always resolve a symbol frame, why I frame is the idea of standard red?

Time:02-24

The purpose is to realize the above place a button on a panel, a circle, click on the button, the color will change, in the round
But after I joined the implement, after listening to the click call function: the actionPerformed () will display frame marked red, connot resolve symbol frame, could you tell me how to modify?


Code:
 
The import javax.mail. Swing. *;
import java.awt.*;
Import the Java. The awt. Event. An ActionEvent;
Import the Java. The awt. Event. ActionListener;

The class MyDrawPanel extends JPanel {
Public void paintComponent (Graphics g) {
Graphics2D Graphics2D=g (Graphics2D);
Int red=(int) (Math. The random () * 255);
Int green=(int) (Math. The random () * 255);
Int blue=(int) (Math. The random () * 255);
Color startColor=new Color (red, green, blue);

Red=(int) (Math. The random () * 255);
Green=(int) (Math. The random () * 255);
Blue=(int) (Math. The random () * 255);
Color endColor=new Color (red, green, blue);

GradientPaint GradientPaint=new GradientPaint (70, startColor, 150150, endColor);
Graphics2D. SetPaint (gradientPaint);//the virtual brush painting gradually layer
Graphics2D. FillOval,70,100,100 (70);//use the brush to fill the oval area
}
}

Public class SimpleGUI implements ActionListener {
Public static void main (String [] args) {
SimpleGUI GUI=new SimpleGUI ();
GUI. The go ();
}

Public void actionPerformed (an ActionEvent event) {
Frame. The repaint ();
}

//rewrite JPanel, join the style we need

Public void the go () {
JFrame frame=new JFrame ();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//set off or stop

JButton button=new JButton (" do not click ");
Button. AddActionListener (this);
MyDrawPanel mypanel=new MyDrawPanel ();//create our myPanel object

Frame. The add (BorderLayout. CENTER, mypanel);//add into the frame of the frame
Frame. The add (BorderLayout. SOUTH, the button).

Frame. The setSize (300300);
frame.setVisible(true);//set the framework for visible
}

}

Without the operation result of the interface:


The book instance

  • Related