ネタ心者歓迎! 今更ながらにJava相談室

このエントリーをはてなブックマークに追加
249名無しの学生さん(♀)
class CustomGraphics extends JPanel{
int x1, y1, x2, y2;
Kadai5b top;
CustomGraphics(Kadai5b t){
top = t;
setBackground (Color.white);
setMinimumSize (new Dimension(500, 500));
setPreferredSize(new Dimension(500, 500));
addMouseListener(new MyMouse());
addMouseMotionListener(new MyMouse());
}

public void paintComponent(Graphics g){
super.paintComponent(g);
int xx, yy, xsize, ysize;
if (x1 < x2 ) {
xx = x1;
xsize = x2 - x1;
} else {
xx = x2;
xsize = x1 - x2;
}
if (y1 < y2) {
yy = y1;
ysize = y2 - y1;
} else {
yy = y2;
ysize = y1 - y2;
}
if (top.bp.type == 'r'){
g.setColor(top.cp.fillColor);
g.fillRect(xx, yy, xsize, ysize);
g.setColor(top.cp.drawColor);
g.drawRect(xx, yy, xsize, ysize);
} else if (top.bp.type == 'o'){
g.setColor(top.cp.fillColor);
g.fillOval(xx, yy, xsize, ysize);
g.setColor(top.cp.drawColor);
g.drawOval(xx, yy, xsize, ysize);
} else if (top.bp.type == 'l'){
g.setColor(top.cp.drawColor);
g.drawLine(x1, y1, x2, y2);
}
}
}