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

このエントリーをはてなブックマークに追加
251名無しの学生さん(♀)
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()];
}
}
}