Hey, so when i attempt to use the BorderLayout, then run the program nothing is shown in the window, my slider/textboxes and labels are gone. Then when i revert back to using a FlowLayout, they come back.
package calculations; import java.awt.*; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class MyControlPanel extends javax.swing.JPanel { private MyShape theShape;//creating instance of MyShape static int min = 0;//minimum value for jSlider static int max = 100;//maximum value for jSlider static int initial = 0;//inital value for jSlider //creating components JSlider jSlider; JLabel jLabel1; JLabel jLabel2; JLabel jLabel3; JLabel jLabel4; JTextField jText1; JTextField jText2; private int shapeSize;//used to hold sliderValue DrawShape drawShape = new DrawShape(20,20,shapeSize,theShape); public MyControlPanel() { initComponents(); //JSlider setup jSlider = new JSlider(JSlider.HORIZONTAL, min, max, initial); jSlider.setMajorTickSpacing(10); jSlider.setMinorTickSpacing(1); jSlider.setPaintLabels(true); jSlider.setPaintTicks(true); jSlider.setValue(50); jSlider.addChangeListener(new MyChangeAction()); //create instance of jTexts jText1 = new JTextField(); jText2 = new JTextField(); //setText for jTexts jText1.setText(" "); jText2.setText(" "); //create instance of labels jLabel1 = new JLabel(); jLabel2 = new JLabel(); jLabel3 = new JLabel(); jLabel4 = new JLabel(); //setText for jLabels jLabel1.setText("Shape Dimension = "); jLabel2.setText(" Boundary Length = "); jLabel3.setText(" Area = "); jLabel4.setText(""); //adding components this.add(jSlider); this.add(jLabel1); this.add(jLabel4); this.add(jLabel2); this.add(jText1); this.add(jLabel3); this.add(jText2); //this.add(drawShape); setLayout(new FlowLayout()); repaint(); } public void setShape(MyShape suppliedShape) { theShape = suppliedShape; } public MyShape getShape() { return theShape; } public class MyChangeAction implements ChangeListener { @Override public void stateChanged(ChangeEvent e) { DrawShape drawShape = new DrawShape(20,20,shapeSize,theShape); int sliderValue = jSlider.getValue(); shapeSize = sliderValue; double area; double boundaryLength; String str = Double.toString(sliderValue); jLabel4.setText(str); area = theShape.getArea(sliderValue); boundaryLength = theShape.getBoundaryLength(sliderValue); jText1.setText(Double.toString(Math.round(boundaryLength))); jText2.setText(Double.toString(Math.round(area))); add(drawShape); } } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) ); }// </editor-fold> // Variables declaration - do not modify // End of variables declaration }
this is my code with the FlowLayout, can someone tell me how i would implement the BorderLayout correctly, so that my program looks something like this:
Currently:
What i would like:
Slider/textboxes and labels at the bottom, but the paint panel at above it.
Thanks in advance! Any help would be great!