-
Assign 105 : Pict~
ยาวไป + ยากไปหน่อย เด่วทำอีกอันที่มาน ง่ายก่านี้ไว้นา
[src]
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ToonyPic
extends JFrame implements ActionListener,WindowListener
{
JFrame ff = new JFrame("Toony's Link World");
JPanel pn[] = {new JPanel(),new JPanel()};
JButton bb = new JButton("OK");
JList jl[] = {new JList(),new JList()};
//GridBagConstraints gc = new GridBagConstraints();
int stx=10,sty=100;
int box,size,color=0,ran=0;
int x=0,w=50,h=50,fill;
int r1,g1,b1;
String R,G,B,W,H;
Button rect = new Button("Rectangle"), oval = new Button("Circle");
Button small = new Button("Small"), medium = new Button("Medium") , large=new Button("Large"),ok1 = new Button("Use your Size!") , xxx=new Button("Fill");
TextField r = new TextField(""),g=new TextField(""),b=new TextField("");
TextField ww = new TextField(""),hh=new TextField("");
Button ok2 = new Button("Use Your Set Color"),red = new Button("Red"), green = new Button("Green"),blue= new Button("Blue"),close= new Button("Close");
public ToonyPic()
{
// #################
-
- -''
[src]
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class testpic
extends JFrame implements ActionListener
{
JFrame ff = new JFrame();
JPanel pn[] = {new JPanel(),new JPanel()};
int box,size,color=0;
int x=0,w=50,h=50,fill;
Button rect = new Button("Rectangle"), oval = new Button("Circle");
Button small = new Button("Small"), medium = new Button("Medium") , large=new Button("Large"), xxx=new Button("Fill / Draw");
Button black = new Button("Black"), red = new Button("Red"), green = new Button("Green"),blue= new Button("Blue"),close= new Button("Close");
public testpic()
{
setSize(520,600);
getContentPane().setLayout(new BorderLayout());
pn[0].setLayout(new GridLayout(2,3));
pn[0].add(rect);
pn[0].add(oval);
pn[0].add(xxx);
pn[0].add(small);
pn[0].add(medium);
pn[0].add(large);
getContentPane().add(pn[0],BorderLayout.NORTH);
rect.addActionListener(this);
oval.addActionListener(this);
xxx.addActionListener(this);
small.addActionListener(this);
medium.addActionListener(this);
large.addActionListener(this);
pn[1].setLayout(new GridLayout(1,2));
pn[1].add(black);
pn[1].add(red);
pn[1].add(green);
pn[1].add(blue);
pn[1].add(close);
getContentPane().add(pn[1],BorderLayout.SOUTH);
black.addActionListener(this);
red.addActionListener(this);
green.addActionListener(this);
close.addActionListener(this);
blue.addActionListener(this);
setVisible(true);
}
public static void main(String[] args)
{
testpic tp = new testpic();
}
public void paint(Graphics g)
{
g.setColor(Color.white);
g.fillRect(10,70,500,500);
if (color==0)
{
g.setColor(Color.black);
}
if (color==1)
{
g.setColor(Color.red);
}
if (color==2)
{
g.setColor(Color.green);
}
if (color==3)
{
g.setColor(Color.blue);
}
if (box==1)
{
if (fill==0)
{
g.drawRect(10,70,w,h);
}
if (fill==1)
{
g.fillRect(10,70,w,h);
}
}
if (box==2)
{
if (fill==0)
{
g.drawOval(10,70,w,h);
}
if (fill==1)
{
g.fillOval(10,70,w,h);
}
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==rect)
{
box=1;
}
if (e.getSource()==oval)
{
box=2;
}
if (e.getSource()==xxx)
{
if (fill==0)
{
fill=1;
}
else if (fill==1)
{
fill=0;
}
}
if (box==1||box==2)
{
if (e.getSource()==small)
{
w=50;
h=50;
}
if (e.getSource()==medium)
{
w=200;
h=200;
}
if (e.getSource()==large)
{
w=400;
h=400;
}
}
{
if (e.getSource()==close)
{
System.exit(0);
}
if (e.getSource()==red)
{
color=1;
}
if (e.getSource()==green)
{
color=2;
}
if (e.getSource()==blue)
{
color=3;
}
if (e.getSource()==black)
{
color=0;
}
}
repaint();
}
}
[/src]