📄 9.9-testovals.java
字号:
// TestOvals.java: Demonstrate drawing ovals
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Graphics;
public class TestOvals extends JFrame
{
// Default constructor
public TestOvals()
{
setTitle("Show Ovals");
getContentPane().add(new OvalsPanel());
}
// Main method
public static void main(String[] args)
{
TestOvals frame = new TestOvals();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(250, 250);
frame.setVisible(true);
}
}
// The class for drawing the ovals on a panel
class OvalsPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponents(g);
g.drawOval(10, 30, 100, 60);
g.drawOval(130, 30, 60, 60);
g.setColor(Color.yellow);
g.fillOval(10, 130, 100, 60);
g.fillOval(130, 130, 60, 60);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -