custompanel.java

来自「Java语言」· Java 代码 · 共 29 行

JAVA
29
字号

// A customized JPanel class.
import java.awt.*;
import javax.swing.*;

public class CustomPanel extends JPanel {
   public final static int CIRCLE = 1, SQUARE = 2;
   private int shape;

   public void paintComponent( Graphics g )
   {
      super.paintComponent( g );

      if ( shape == CIRCLE )
         g.fillOval( 50, 10, 60, 60 );
      else if ( shape == SQUARE )
         g.fillRect( 50, 10, 60, 60 );
   }

   public void draw( int s )
   {
      shape = s;
      repaint();
   }
}



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?