below is the code i currently have for the drawing class, iv been looking for documents which teach me how to create 3 shapes on screen.
i have a jframe, with menus to select the shape (seen below) ect.
if (clickedMenu.getText().equals("Square")){
value = pane.returnslider();
shape = new ASquare(value);
so my question is: how to i edit the below class to create a 2D square that appears on my Jframe which changes size depending on the slider value?
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package assignment;
import java.awt.Graphics;
/**
*
* @author Steven
*/
public class MyDrawing extends javax.swing.JPanel {
/**
* Creates new form MyDrawing
*/
@Override public void paintComponent(Graphics g) {
super.paintComponent(g); // paints background
}
}
some code from my jpanel that would maybe help you in answering my question:
public class MyChangeAction implements ChangeListener {
//complete code here
@Override
public void stateChanged(ChangeEvent ce) {
double value = slider.getValue();
String str = Double.toString(value);
sliderLabel.setText(str);
DecimalFormat df = new DecimalFormat("0.0");
boundary_length.setText("" + df.format(MyFrame.shape.computeBoundaryLength(value)));
area.setText("" + df.format(MyFrame.shape.computeArea(value)));
}
} // end class
public double returnslider() {
return slider.getValue();
}
my square class:
package assignment;
import java.awt.event.ActionListener;
/**
*
* @author b00560806
*/
public class ASquare extends MyShape {
double value;
public ASquare(double value) {
this.value = value;
}
@Override
public double computeBoundaryLength(double Length)
{
thelength=(4*Length);
return thelength;
}
@Override
public double computeArea(double Length)
{
thearea=(Length*Length);
return thearea;
}
}
Try this: