gui.java

来自「一个大学本科java课程的大作业。要求利用GUI以及APPLET分别完成一个任务」· Java 代码 · 共 77 行

JAVA
77
字号

/**
 *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 + =
减小字号Ctrl + -
显示快捷键?