{
@Override
public void mousePressed(MouseEvent e) {
model.setX((e.getX()-model.getOrigin().getX())/model.getStep());
model.setY((e.getY()-model.getOrigin().getY())/model.getStep());
model.addPoint(new Mark(model.getX(), model.getY()));
update();
}
};
plot.addMouseListener(mouseAdapter);
plot.addMouseMotionListener(mouseAdapter);
lblR = new JLabel();
lblR.setText("R: ");
lblR.setForeground(Color.WHITE);
lblR.setBorder(BorderFactory.createEmptyBorder(0, 10 , 0 ,10));
sliderR = new JSlider(1,10);
sliderR.setValue(1);
ChangeListener sliderRListener = new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
model.setR((Integer)sliderR.getValue());
update();
}
};
sliderR.addChangeListener(sliderRListener);
sliderR.setMaximumSize(new Dimension(350,25));
header.add(lblR);
header.add(sliderR);
lblX = new JLabel();
lblX.setText("X: ");
lblX.setForeground(Color.WHITE);
lblX.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
String choices[] = {"0","1","2","-1","-2","-3"};
comboX = new JComboBox<String>();
for (int i = 0; i < choices.length; i++)
comboX.addItem (choices[i]);
comboX.addItemListener(new ItemListener(){
@Override
public void itemStateChanged(ItemEvent e)
{
String item = (String)comboX.getSelectedItem();
model.setX(Integer.valueOf(item));
model.setSelectedX(model.getX());
model.setY(model.getSelectedY());
model.addPoint(new Mark(model.getX(),model.getY()));
update();
}
});
comboX.setMaximumSize(new Dimension(150, 25));
header.add(lblX);
header.add(comboX);
lblY = new JLabel();
lblY.setText("Y: ");
lblY.setForeground(Color.WHITE);
lblY.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
header.add(lblY);
groupY = new ButtonGroup();
ActionListener radioButtonActionListner = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
String command = evt.getActionCommand();
model.setY(Integer.valueOf(command));
model.setSelectedY(model.getY());
model.setX(model.getSelectedX());
model.addPoint(new Mark(model.getX(),model.getY()));
update();
}
};
String radioButtonContraints[] = {"-2","-1","0","1","2"};
JRadioButton radioButton = new JRadioButton(radioButtonContraints[0]);