📄 rectdemo.java
字号:
import javax.swing.*;import java.awt.*;public class RectDemo extends JFrame { RectPanel drawPanel = new RectPanel(); public RectDemo() { super("绘制各种矩形"); setSize(300,260); this.getContentPane().add(drawPanel); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { RectDemo rd = new RectDemo(); rd.setVisible(true); } class RectPanel extends JPanel { public void paintComponent(Graphics g){ super.paintComponent(g); g.setColor(Color.white); g.drawRect(8, 8, getSize().width/2 - 18, getSize().height/3 - 18); g.drawRoundRect(8,getSize().height/3, getSize().width/2 - 18, getSize().height/3 - 18, 30, 20); g.draw3DRect(8, getSize().height/3 * 2, getSize().height/2 - 18,getSize().height/3 - 18, false); g.draw3DRect(getSize().width/2, getSize().height/3 * 2, getSize().width/2 - 18, getSize().height/3 - 18, true); g.setColor(Color.green); g.fillRect(getSize().width/2, 8, getSize().width/2 - 18, getSize().height/3 - 18); g.fillRoundRect(getSize().width/2, getSize().height/3, getSize().width/2 - 18, getSize().height/3 - 18, 30, 20); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -