package Graph;
import java.awt.Graphics;
import java.awt.Polygon;
import javax.swing.JFrame;
import javax.swing.JPanel;
Below here is my class which covers all other classes, and extends JFrame, which I have created by selecting "new > Java Frame" options in Netbeans.I created this in a package called Graph, and this filename is GraphFrame.Java.
public class GraphFrame extends javax.swing.JFrame {
public GraphFrame() {
}
The lines below is from my JFrame auto creating codes.
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
These lines below here is my main method
public static void main(String args[]) {
/* Create and display the form */
//java.awt.EventQueue.invokeLater(new Runnable() {
//public void run() {
GraphFrame Frame=new GraphFrame();
Frame.setVisible(true);
Frame.setTitle("Functional Dependency");
Frame.setSize(500, 500);
//}
// });
}
These lines is my DrawGraph class, which I created INSIDE the GraphFrame class. Besides that, it extends my JPanel which I made by dragging the JPanel icon from the Swing Containers (Sorry if that is the wrong way to add JPanel)
class DrawGraph extends JPanel{
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawLine(10, 100, 380, 100);
g.drawLine(200, 30, 200, 190);
g.drawLine(380, 100, 370, 90);
g.drawLine(380, 100, 370, 110);
g.drawLine(200, 30, 190, 40);
g.drawLine(200, 30, 210, 40);
g.drawString("X", 360, 80);
g.drawString("Y", 220, 40);
}
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
My problem is, the lines of graph which I have coded, did not appear.I have googled, StackOverflowed, browsed through my lab exercises, and I can't seem to find the solution to this. Yes, this may need more reading, but to be honest, I couldn't quite understand what's wrong.