250 :
名無しの学生さん(♀):
class MyMouse extends MouseAdapter{
public void mousePressed(MouseEvent e){
x1 = e.getX();
y1 = e.getY();
}
public void mouseDragged(MouseEvent e){
x2 = e.getX();
y2 = e.getY();
repaint();
}
public void mouseMoved (MouseEvent e){ }
public void mouseReleased(MouseEvent e){ }
public void mouseClicked (MouseEvent e){ }
public void mouseEntered (MouseEvent e){ }
public void mouseExited (MouseEvent e){ }
}
class ButtonPanel extends JPanel{
JButton lineB, rectB, ovalB;
int type = 'r';
InListener listener;
ButtonPanel(){
rectB = new JButton("四角");
ovalB = new JButton("楕円");
lineB = new JButton("直線");
listener = new InListener();
rectB.addActionListener(listener);
ovalB.addActionListener(listener);
lineB.addActionListener(listener);
add(rectB);
add(ovalB);
add(lineB);
}
}
class InListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
if (e.getSource() == rectB) { type = 'r'; }
else if (e.getSource() == ovalB) { type = 'o'; }
else if (e.getSource() == lineB) { type = 'l'; }
}
}
251 :
名無しの学生さん(♀):01/11/04 18:31
class ComboPanel extends JPanel{
int drawInit = 1, fillInit = 0;
JLabel drawL, fillL;
JComboBox drawC, fillC;
JPanel drawP, fillP;
InListener1 listener1;
Color[] name = {Color.white, Color.black, Color.red, Color.yellow, Color.green, Color.blue};
Color drawColor = name[drawInit], fillColor = name[fillInit];
ComboPanel(){
String[] list = {"なし","黒","赤","黄","緑","青"};
drawL = new JLabel("線の色 ");
drawC = new JComboBox(list);
drawC.setSelectedIndex(drawInit);
drawC.addActionListener(listener1);
drawP = new JPanel();
drawP.setLayout(new GridLayout(2,1));
drawP.add(drawL);
drawP.add(drawC);
add(drawP);
fillL = new JLabel("塗りつぶしの色");
fillC = new JComboBox(list);
fillC.setSelectedIndex(fillInit);
fillC.addActionListener(listener1);
fillP = new JPanel();
fillP.setLayout(new GridLayout(2,1));
fillP.add(fillL);
fillP.add(fillC);
add(fillP);
}
}
class InListener1 implements ActionListener{
public void actionPerformed(ActionEvent e) {
drawColor = name[drawC.getSelectedIndex()];
fillColor = name[fillC.getSelectedIndex()];
}
}
}