Note that there are some explanatory texts on larger screens.

plurals
  1. POI have a JApplet which has to display 3 Components. (2 JPanels and 1 Paint Method)
    primarykey
    data
    text
    <p>I have an assignment in which I have to allow a user to plot a graph using a quadratic equation.</p> <p>I managed to draw the skeleton of the graph, and now I am trying to display the "control panel" for the user to input the values.</p> <p>I have 4 files:</p> <ul> <li><code>graph.java</code></li> <li><code>panel.java</code></li> <li><code>panelB.java</code></li> <li><code>panelC.java</code></li> </ul> <p>My problem is when I run the code it is displaying only the <code>panel.java</code> even in the container where it should display the other two panels.</p> <h3>panel.java</h3> <pre><code>import java.awt.Dimension; import java.awt.Graphics; import java.awt.*; import java.awt.geom.*; import javax.swing.JPanel; public class panel extends JPanel { public panel(){ this.setBackground(Color.yellow); } } </code></pre> <p>Can anyone please advise what changes I should do to fix this problem?</p> <p>I have done some changes to the graph.java file:</p> <pre><code>import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import javax.swing.*; public class GraphApplet extends JApplet{ public GraphApplet(){ raph p = new Graph();//graph p.setPreferredSize(new Dimension(760,500)); conn.add(p,BorderLayout.CENTER); } </code></pre> <p>And now all that is being displayed is the graph.</p> <p>Regarding the other code, I also made some changes to the class names:</p> <p><strong>gnjk;.java</strong></p> <pre><code>import java.awt.Dimension; import java.awt.Graphics; import java.awt.*; import java.awt.geom.*; import javax.swing.JPanel; public class Graph extends JPanel { public Graph(){ this.setBackground(Color.yellow); } public void paintComponent(Graphics p) { super.paintComponent(p); Graphics2D graph = (Graphics2D)p; this.setBackground(Color.yellow);//set background color. int x,y,y1,x1,a,b,p1x,p1y,p2x,p2y; int xstart = 7; int ystart = 1; int xfinish = 3; </code></pre> <p>.......</p> <p><strong>bhfvhn.java</strong></p> <pre><code>import javax.swing.*; import java.awt.*; import javax.swing.JPanel; public class ControlsA extends JPanel{ public void init (Box g) { a = Box.createVerticalBox(); a.add(new JLabel("Please enter the values below:")); a.add(new JLabel("h")); } } </code></pre> <p><strong>jknmk.java</strong></p> <pre><code>import javax.swing.*; import java.awt.Component; import java.awt.Dimension; public class ControlsB extends JPanel{ public void init (Box b) { b = Box.createHorizontalBox(); b.add(new JLabel("a")); JTextField f1 = new JTextField("0.0"); f1.setMaximumSize(new Dimension(100,30)); b.add(f1); } } </code></pre> <hr> <p>Here is an updated to my project:</p> <p><strong>jkl.java</strong></p> <pre><code>import java.awt.BorderLayout; import java.awt.Container; public class GraphApplet extends JApplet{ public GraphApplet() { public void init(){ SwingUtilities.invokeLater(new Runnable() { public void run(){ Container conn = getContentPane(); conn.setLayout(new BorderLayout()); Graph z = new Graph(); conn.add(p,BorderLayout.CENTER); fasfae a = new ControlsA(box1); conn.add(a,BorderLayout.LINE_START); adsfawef b = new ControlsB(box2); conn.add(b,BorderLayout.PAGE_END); } }); } } /*Container conn = getContentPane(); conn.setLayout(new BorderLayout()); Graph p = new Graph();//graph p.setPreferredSize(new Dimension(460,560)); conn.add(p,BorderLayout.CENTER); Box a = new Box(BoxLayout.Y_AXIS); a.setPreferredSize(new Dimension(50,50)); conn.add(a,BorderLayout.EAST); Box b = new Box(BoxLayout.X_AXIS); b.setPreferredSize(new Dimension(201,50)); conn.add(b,BorderLayout.SOUTH);*/ //this code is commented not to loose it </code></pre> <p><strong>vtk.java</strong></p> <pre><code>import java.awt.Dimension; import java.awt.Graphics; import java.awt.*; import java.awt.geom.*; import javax.swing.JPanel; class Graph extends JPanel { public Graph(){ this.setBackground(Color.yellow); } @Override public Dimension getPreferredSize(){return (new Dimension(460,560)); } public void paint(Graphics z) { Graphics graph = (Graphics2D)z; this.setBackground(Color.yellow). int x,y,y1,x1,a,b,p1x,p1y,p2x,p2y; //line co-ordinates //the numbers represent the number of boxes on the graph int xstart = 7; int ystart = 1; int x = 3; int y = 9; //other variables int i = 0; int i2 = 0; int m = 0; int n = 0; int m2 = 0; int n2 = 0; int f2 = 0; int g2 = 1; //ranges int f = 5; int g = -5; //change -ve num to +ve int g3 = Math.abs(g); int a1 = g3 + f; int b1 = a1; a = (Height); f = (Width); } } } // 6 variables the user has to input } @Override public Dimension getPreferredSize() {return (new Dimension(200,100));} } </code></pre> <p><strong>nllkl.java</strong></p> <pre><code> @Override public Dimension getPreferredSize(){return (new Dimension(201,50));} } </code></pre> <p>Still no improvement. I cannot understand what is going on.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload