用Java画一个静态的月亮。
答案:1 悬赏:0 手机版
解决时间 2021-01-08 05:39
- 提问者网友:最爱你的唇
- 2021-01-07 10:00
用Java画一个静态的月亮。
最佳答案
- 五星知识达人网友:你可爱的野爹
- 2021-01-07 10:18
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
public class MyPaint extends JPanel{
private static final long serialVersionUID = 1649513015796308922L;
public MyPaint() {
// TODO Auto-generated constructor stub
this.setBackground(Color.BLACK);
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
g.setColor(Color.YELLOW);
g.fillOval(50, 50, 50, 50);
g.setColor(Color.BLACK);
g.fillOval(70, 50, 50, 50);
}
}
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JFrame;
public class MyFrame extends JFrame{
private static final long serialVersionUID = 3202551557638252826L;
MyPaint mp=new MyPaint();
public MyFrame() {
// TODO Auto-generated constructor stub
this.setSize(100,150);
Container container=getContentPane();
container.add(mp,BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
MyFrame mf=new MyFrame();
mf.setVisible(true);
}
}
import java.awt.Graphics;
import javax.swing.JPanel;
public class MyPaint extends JPanel{
private static final long serialVersionUID = 1649513015796308922L;
public MyPaint() {
// TODO Auto-generated constructor stub
this.setBackground(Color.BLACK);
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
g.setColor(Color.YELLOW);
g.fillOval(50, 50, 50, 50);
g.setColor(Color.BLACK);
g.fillOval(70, 50, 50, 50);
}
}
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JFrame;
public class MyFrame extends JFrame{
private static final long serialVersionUID = 3202551557638252826L;
MyPaint mp=new MyPaint();
public MyFrame() {
// TODO Auto-generated constructor stub
this.setSize(100,150);
Container container=getContentPane();
container.add(mp,BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
MyFrame mf=new MyFrame();
mf.setVisible(true);
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯