编写java小程序 将窗口右上1/4区域用红色画出实心的长方形,将窗口左下1/4区域用红色画出实心的长方形
时间: 2023-11-27 11:53:07 浏览: 72
|
| estimate |
| evade |
| evaluate |
| evaporate |
| even |
| eventuate |
| evict |
| evidence |
| evoke |
| evolve |
| exaggerate |
| examine |
| exceed以下是一个简单的 Java 程序,可以实现你的要求:
```java
import java.awt.Color;
import java.awt |
| excite |
| exclude |
| excuse |
| execute |
| exempt |
| exert |
|.Dimension;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class DrawRectangle extends JPanel {
public DrawRectangle() exhaust |
| exhilarate |
| exist |
| exit |
| expand |
| expect |
| expedite {
setPreferredSize(new Dimension(400, 400)); // 设置窗口大小
}
@Override
protected void paintComponent |
| expend |
| experience |
| expire |
| explain |
| explode |
| exploit |
| explore (Graphics g) {
super.paintComponent(g);
int width = getWidth();
int height = getHeight();
g.setColor(Color.RED);
|
| export |
| expose |
| expound |
| express |
| extend |
| extinguish |
| extract g.fillRect(width / 2, 0, width / 2, height / 2); // 右上1/4区域
|
| extradite |
| extrapolate |
| fabricate |
| face |
| facilitate |
| fade |
| fail |
| faint |
| fake |
| fall |
| falsify |
| falter |
| familiar g.fillRect(0, height / 2, width / 2, height / 2); // 左下1/4区域ize |
| fancy |
| fare |
| fascinate |
| fashion |
| fasten |
| father |
}
public static void main(String[] args) {
JFrame frame = new JFrame("Draw Rectangle");
frame.setDefaultCloseOperation(JFrame| fault |
| favor |
| fear |
| feast |
| federate |
| feed |
| feel .EXIT_ON_CLOSE);
frame.add(new DrawRectangle());
frame.pack();
frame.setVisible(true);
}
}
```
运行该程序 |
| feign |
| felicitate |
| fell |
| fence |
| fend |
| ferment |
|,将会打开一个窗口,在右上1/4区域和左下1/4区域分别绘制了一个红色的实心长方形。
阅读全文