Created
August 21, 2011 10:09
-
-
Save kurochan/1160427 to your computer and use it in GitHub Desktop.
Javaでロボットを描いてみよう!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color; | |
import java.awt.Container; | |
import java.awt.Font; | |
import java.awt.Graphics; | |
import java.awt.event.WindowAdapter; | |
import java.awt.event.WindowEvent; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
public class DrawRobotSample extends JFrame { | |
public DrawOvalSample() { | |
setSize(400, 300); | |
setTitle("ロボットを描いてみよう!"); | |
addWindowListener(new WindowAdapter() { | |
public void windowClosing(WindowEvent e) { | |
System.exit(0); | |
} | |
}); | |
MyJPanel myJPanel = new MyJPanel(); | |
Container c = getContentPane(); | |
c.add(myJPanel); | |
} | |
public static void main(String[] args) { | |
JFrame w = new DrawOvalSample(); | |
w.setVisible(true); | |
} | |
public class MyJPanel extends JPanel { | |
public MyJPanel() { | |
setBackground(Color.WHITE); | |
} | |
// オーバーライドしたメソッド | |
public void paintComponent(Graphics g) { | |
super.paintComponent(g); | |
g.setColor(Color.GREEN); | |
g.fillOval(140, 20, 120, 120); | |
g.setColor(Color.WHITE); | |
g.fillRect(140, 80, 120, 70); | |
g.setColor(Color.GREEN); | |
g.fillRect(140, 90, 120, 100); | |
g.fillOval(110, 90, 20, 20); | |
g.fillOval(270, 90, 20, 20); | |
g.fillRect(110, 100, 20, 60); | |
g.fillRect(270, 100, 20, 60); | |
g.fillOval(110, 150, 20, 20); | |
g.fillOval(270, 150, 20, 20); | |
g.fillRect(160, 190, 20, 30); | |
g.fillRect(220, 190, 20, 30); | |
g.fillOval(160, 210, 20, 20); | |
g.fillOval(220, 210, 20, 20); | |
g.setColor(Color.WHITE); | |
g.fillOval(165, 45, 15, 15); | |
g.fillOval(215, 45, 15, 15); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment