Hi, I am stuck on creating the Jslider, when i compile the code i get an error on "else if (e.getSource() == value) {"which says the symbol variable of value.Also, when i run the programme to change colour the colour doesnt change and i get some errors on a diffrent window, please check my code and see where am going wrong.
thanks
thanks
// Class definition
public class ExampleSolution8_2 extends JPanel implements ActionListener {
private JButton moveLeft, moveRight, makeBigger, makeSmaller;
private JComboBox shapeChoice;
private JComboBox colourChoice;
private Shape colour;
private Point firstPoint;
private Circle firstCircle;
private Square firstSquare;
private Doughnut firstDoughnut;
private Triangle firstTriangle;
private Rectangle firstRectangle;
private Point aShape;
private Point Colour;
private JSlider slider;
private int Value = 1 ;
private int minimumvalue = 1 ;
private int maximumvalue = 100;
private int initvalue = 0;
// Constructor method declaration
public ExampleSolution8_2() {
/// moveLeft = new JButton("Move Left");
////add(moveLeft);
////moveLeft.addActionListener(this);
//// moveRight = new JButton("Move Right");
///add(moveRight);
///moveRight.addActionListener(this);
////makeBigger = new JButton("Make Bigger");
///add(makeBigger);
////makeBigger.addActionListener(this);
////makeSmaller = new JButton("Make Smaller");
///add(makeSmaller);
///makeSmaller.addActionListener(this);
shapeChoice = new JComboBox();
shapeChoice.addItem("Point");
shapeChoice.addItem("Square");
shapeChoice.addItem("Circle");
shapeChoice.addItem("Doughnut");
shapeChoice.addItem("Triangle");
shapeChoice.addItem("Rectangle");
add(shapeChoice);
shapeChoice.addActionListener(this);
colourChoice = new JComboBox();
colourChoice.addItem("Black");
colourChoice.addItem("Red");
colourChoice.addItem("Green");
colourChoice.addItem("Blue");
colourChoice.addItem("Yellow");
colourChoice.addItem("Purple");
add(colourChoice);
colourChoice.addActionListener(this);
aShape = Colour;
// Instantiate shape classes
firstPoint = new Point();
firstCircle = new Circle();
firstSquare = new Square();
firstDoughnut = new Doughnut();
firstTriangle = new Triangle();
firstRectangle = new Rectangle();
// Initially assign aShape a Point object
aShape = firstPoint;
// Local variable declarations
// Instantiate a slider using Swing class JSlider
slider = new JSlider(JSlider.HORIZONTAL, 100, 10);
add(slider);
// Add the slider to the north portion of the JPanel
///add(slider, BorderLayout.NORTH);
// Create a new window using the Swing class JFrame and add this panel
makeFrame();
}
public void actionPerformed(ActionEvent e) {
// Manipulate respective object when buttons pressed
if (e.getSource() == moveLeft) {
aShape.moveXY(-20, 0);
}
else if (e.getSource() == moveRight) {
aShape.moveXY(20, 0);
}
else if (e.getSource() == makeBigger) {
aShape.reSize(20);
}
else if (e.getSource() == makeSmaller) {
aShape.reSize(-20);
}
// checkbox assigns object to aShape
else if (e.getSource() == shapeChoice) {
if (shapeChoice.getSelectedItem().equals("Circle"))
aShape = firstCircle;
else if (shapeChoice.getSelectedItem().equals("Square"))
aShape = firstSquare;
else if (shapeChoice.getSelectedItem().equals("Point"))
aShape = firstPoint;
else if (shapeChoice.getSelectedItem().equals("Doughnut"))
aShape = firstDoughnut;
else if (shapeChoice.getSelectedItem().equals("Triangle"))
aShape = firstTriangle;
else if (shapeChoice.getSelectedItem().equals("Rectangle"))
aShape = firstRectangle;
}
{
if (e.getSource() == colourChoice) {
if (colourChoice.getSelectedItem().equals("Black"))
aShape = Colour;
else if (colourChoice.getSelectedItem().equals("Red"))
aShape = Colour;
else if (colourChoice.getSelectedItem().equals("Green"))
aShape = Colour;
else if (colourChoice.getSelectedItem().equals("Yellow"))
aShape = Colour;
else if (colourChoice.getSelectedItem().equals("Purple"))
aShape = Colour;
}
else if (e.getSource() == value) {
}
{ if (slider.getValue() >= 20) aShape.reSize(20);
if (slider.getValue() >= 30) aShape.reSize(20);
aShape.reSize(20);
if (slider.getValue() >= 40) aShape.reSize(20);
aShape.reSize(20);
if (slider.getValue() >= 50) aShape.reSize(20);
aShape.reSize(20);
if (slider.getValue() < 60)
aShape.reSize(20);
}
{
// if (e.getSource() == colorChoice)
{
// Ask Java to repaint the window to reflect the updates made
repaint();
}
}
}}
// Provide this method to instruct Java what to do when repainting the window
public void paintComponent(Graphics g) {
super.paintComponent(g);
// Call the respective methods from respective class to print the new co-ordinate values
aShape.outputXYCoords(g);
// Call the respective methods from respective class to redraw the shape
aShape.display(g);
// Call the respective methods to redraw the shapeColour
//g.setColour(Color);
add(slider, BorderLayout.NORTH);
}
// Create a window frame
public void makeFrame() {
// Instantiate a window frame using Swing class JFrame
JFrame frame = new JFrame("ExampleSolution8_2");
// When the window is closed terminate the application
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
// set initial size of window
frame.setSize(800, 600);
// add the current object to the centre of the frame and make visible
frame.getContentPane().add(this, BorderLayout.CENTER);
frame.setVisible(true);
}
}