📄 gui.java
字号:
/**
*Title:Gui.java
*Descriprion:This class is a GUI application
*@author: Peng yu
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Gui implements ActionListener
{
static JFrame myFrame; //creat a JFrame
static DrawingPanel myDrawingPanel; //creat a Panel
public static void main(String args[])
{
Gui myGui=new Gui(); //creat a new instance
myGui.go();
}
/**
* This method run the class,
* it will repaint the shapes once click the button
*/
public void go()
{
myDrawingPanel=new DrawingPanel();
myDrawingPanel.setVisible(false); //the shapes are not visible at the beginning
myFrame=new JFrame("Question2 MiniProject");
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton myButton = new JButton("Draw New Shapes");
//add the panel as well as the button onto the frame
myFrame.getContentPane().add(myDrawingPanel);
myFrame.getContentPane().add(BorderLayout.SOUTH, myButton);
myButton.addActionListener(this); //once click the button,call actionPerformed
myFrame.setSize(400, 400);
myFrame.setVisible(true);
}
/**
* This method response the action the button.
* it will repaint the shapes
* @param event the action that we click the button
*/
public void actionPerformed(ActionEvent event)
{
myDrawingPanel.setVisible(true); //now make the shapes visible
myFrame.repaint(); //repaint the shapes
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -