怎么在java里画出小圆点
答案:1 悬赏:0 手机版
解决时间 2021-03-31 22:30
- 提问者网友:你挡着我发光了
- 2021-03-31 16:26
怎么在java里画出小圆点
最佳答案
- 五星知识达人网友:忘川信使
- 2021-03-31 17:23
package test;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class PaintDemo extends JFrame{
private static final long serialVersionUID = -95348909224392777L;
JPanel c=canvas();
public PaintDemo(){
this.setTitle("Small point paint test");
int w=300,h=300;
this.setSize(w, h);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setSize(w,h);
this.setLocation(screenSize.width / 2 - w / 2,
screenSize.height / 2 - h / 2);
this.setLayout(null);
this.add(this.c);
this.c.setBounds(0, 0, 300, 300);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
this.setVisible(true);
}
public JPanel canvas() {
JPanel panel = new JPanel() {
private static final long serialVersionUID = 1L;
@Override
public void paint(Graphics g) {
super.paint(g);
g.fillOval(100, 100, 100, 100);
}
};
return panel;
}
public static void main(String[] args) {
new PaintDemo();
}
}
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class PaintDemo extends JFrame{
private static final long serialVersionUID = -95348909224392777L;
JPanel c=canvas();
public PaintDemo(){
this.setTitle("Small point paint test");
int w=300,h=300;
this.setSize(w, h);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setSize(w,h);
this.setLocation(screenSize.width / 2 - w / 2,
screenSize.height / 2 - h / 2);
this.setLayout(null);
this.add(this.c);
this.c.setBounds(0, 0, 300, 300);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
this.setVisible(true);
}
public JPanel canvas() {
JPanel panel = new JPanel() {
private static final long serialVersionUID = 1L;
@Override
public void paint(Graphics g) {
super.paint(g);
g.fillOval(100, 100, 100, 100);
}
};
return panel;
}
public static void main(String[] args) {
new PaintDemo();
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯