질문할 곳이 없어서 ㅜㅜ 여기에 또 오립니다.
package paint;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
class DrawInfo implements Serializable{
private int xs, ys, xe, ye;
private Color color;
private JButton jb;
private boolean fill;
public DrawInfo(int xs, int ys, int xe, int ye, Color color, JButton jb, boolean fill){
this.xs=xs;
this.ys=ys;
this.xe=xe;
this.ye=ye;
this.color=color;
this.jb=jb;
this.fill=fill;
}
public void setXSTart(int xs){
this.xs=xs;
}
public void setYSTart(int ys){
this.ys=ys;
}
public void setXEnd(int xe){
this.xe=xe;
}
public void setYEnd(int ye){
this.ye=ye;
}
public void setColor(Color color){
this.color=color;
}
public void setJButton(JButton jb){
this.jb=jb;
}
public void setfill(boolean fill){
this.fill=fill;
}
public int getXSTart(){
return xs;
}
public int getYSTart(){
return ys;
}
public int getXEnd(){
return xe;
}
public int getYEnd(){
return ye;
}
public Color getColor(){
return color;
}
public JButton getJButton(){
return jb;
}
public boolean getfill(){
return fill;
}
}
public class Paint extends JFrame {
private static final long serialVersionUID = 1L;
private JButton pen, circle, square, straight, go, full;// 도구 버튼
private ImageIcon im1, im2, im3, im4, im5, im6, img; // 도구 이미지
private Container con;// 컨테이너
private Canvas can = new Canvas();
private MenuBar mb = new MenuBar();
private Menu file = new Menu("파일");
private MenuItem fnew = new MenuItem("새로열기");
private MenuItem fopen = new MenuItem("불러오기");
private MenuItem fsave = new MenuItem("저장하기");
private MenuItem fexit = new MenuItem("종료하기");
private MenuItem fas = new MenuItem("다른 이름으로 저장");
private Menu option = new Menu("옵션");
private Menu oview = new Menu("보기");
private CheckboxMenuItem pv = new CheckboxMenuItem("확대");
private CheckboxMenuItem mv = new CheckboxMenuItem("축소");
private Menu help = new Menu("도움");
private MenuItem about = new MenuItem("만든사람들");
public int xs, ys, xe, ye, cs;// 좌표
private Color c = new Color(cs);// 색깔
private Vector vc = new Vector();// 도형 변수
private Graphics g; // 그리기를 수행하는 변수
JPanel mt = new JPanel();// 도구 패널
JPanel ct = new JPanel();// 색깔 패널
public Paint(String title) {//프레임 출력 메소드
super("Painting");
this.init();
this.start();
im1 = new ImageIcon("그림판.png");
this.setIconImage(im1.getImage());
this.setSize(1000, 1000);
setVisible(true);
}
public void init() {// 초기화 메소드
im1 = new ImageIcon("그림판.png");
im2 = new ImageIcon("수정됨_연필.png");
im3 = new ImageIcon("수정됨_CriCle.png");
im4 = new ImageIcon("수정됨_사각형.png");
im5 = new ImageIcon("수정됨_직선.png");
im6 = new ImageIcon("수정됨_채우기.png");
// 메뉴바
this.setMenuBar(mb);
mb.add(file);
file.add(fnew);
file.addSeparator();
file.add(fopen);
file.add(fsave);
file.add(fas);
file.add(fexit);
mb.add(option);
option.add(oview);
oview.add(pv);
oview.add(mv);
option.addSeparator();
mb.add(help);
help.add(about);
con = this.getContentPane();
con.setBackground(Color.lightGray);
setLayout(null);
mt();
ct();
canvas();
}
// 캔버스 추가
public void canvas() {
can.setSize(900, 900);
can.setBackground(Color.WHITE);
can.setLocation(40, 50);
add(can);
}
public void mt() { //make tool 버튼 패널
pen = new JButton(im2);
circle = new JButton(im3);
square = new JButton(im4);
straight = new JButton(im5);
full = new JButton(im6);
Dimension di = pen.getPreferredSize();
// 도구 상자 크기
pen.setSize(di);
circle.setSize(di);
square.setSize(di);
straight.setSize(di);
full.setSize(di);
// 도구 상자 위치
pen.setLocation(275, 10);
circle.setLocation(375, 10);
square.setLocation(475, 10);
straight.setLocation(575, 10);
full.setLocation(675, 10);
// 도구상자 추가
con.add("North", pen);
con.add("North", circle);
con.add("North", square);
con.add("North", straight);
con.add("North", full);
// 색깔 상자 추가
}
public void ct() { // Color tool 패널
go = new JButton("Other Color...");
Dimension di2 = go.getPreferredSize();
// 색깔 상자 크기
go.setSize(di2);
// 색깔 상자 위치
go.setLocation(850, 10);
// 색깔 상자
go.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
c = JColorChooser.showDialog(
((Component) e.getSource()).getParent(),
"Color Spectrum", c);
if (c == null)
c = Color.black;
}
});
con.add("East", go);
}
public void start() { //시작 액션 메소드
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.addMouseListener(new handler());
this.addMouseMotionListener(new handler());
// 도구 상자 액션이벤트
pen.addActionListener(new handler());
circle.addActionListener(new handler());
square.addActionListener(new handler());
straight.addActionListener(new handler());
full.addActionListener(new handler());
}
class handler implements MouseListener,
MouseMotionListener, ItemListener, ActionListener {
int width = xe - xs;
int height = ye - ys;
@Override
// action override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object obj = e.getSource();
g.setColor(c);
if (obj==pen)
g.drawLine(xs, xe, ys, ye);
else if (obj == circle) {
if (obj == full) {
g.fillOval(xs, ys, width, height);
} else
g.drawOval(xs, ys, width, height);
} else if (obj == square) {
if (obj == full) {
g.fillRect(xs, ys, width, height);
}
} else
g.drawRect(xs, ys, width, height);
can.repaint();
}
@Override
public void itemStateChanged(ItemEvent e) {
}
@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
xs=e.getX();
ys=e.getY();
can.repaint();
}
@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Paint painted = new Paint("Painting");
}
}
아직 부족한 부분이 많습니다.