Results 1 to 20 of 20
  1. #1
    Megatron's Avatar
    Megatron is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default How I can get a graph plotting attached to a GUI form.....

    HI........

    I need to attach a graph with a GUI form.......

    the target is when user press a button then the graph will appear........

    but I couldn't able to do this........I think i ve messed it up.........

    can anyone point out my errors I ve done.......and give me a corrcted version of my code....I will really be gratefull........

    I pasted my code below.......

    plz help me.........


    Thnx.......













    import java.text.NumberFormat;
    import java.util.Locale;
    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import javax.swing.*;


    /*
    * SamplesJFrame.java
    *
    * Created on January 16, 2015, 2:36 PM
    */



    /**
    *
    * @author Megatron
    */
    public class SamplesJFrame extends javax.swing.JFrame {

    /** Creates new form SamplesJFrame */
    public SamplesJFrame() {
    initComponents();
    }

    /** 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.
    */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    jScrollPane2 = new javax.swing.JScrollPane();
    jTabbedPane1 = new javax.swing.JTabbedPane();
    jPanel1 = new javax.swing.JPanel();
    jlabel11 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jLabel6 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    jTextField2 = new javax.swing.JTextField();
    jTextField1 = new javax.swing.JTextField();
    jButton1 = new javax.swing.JButton();
    jTextField3 = new javax.swing.JTextField();
    jTextField4 = new javax.swing.JTextField();
    jTextField5 = new javax.swing.JTextField();
    jTextField6 = new javax.swing.JTextField();
    jTextField7 = new javax.swing.JTextField();
    jButton2 = new javax.swing.JButton();
    jPanel2 = new javax.swing.JPanel();
    t = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    jLabel9 = new javax.swing.JLabel();
    jMenuBar1 = new javax.swing.JMenuBar();
    jMenu1 = new javax.swing.JMenu();
    jMenuItem1 = new javax.swing.JMenuItem();
    jMenuItem2 = new javax.swing.JMenuItem();
    jMenu2 = new javax.swing.JMenu();
    jMenuBar2 = new javax.swing.JMenuBar();
    jMenu3 = new javax.swing.JMenu();
    jMenuItem3 = new javax.swing.JMenuItem();
    jMenuItem4 = new javax.swing.JMenuItem();
    jMenu4 = new javax.swing.JMenu();
    jMenuBar3 = new javax.swing.JMenuBar();
    jMenu5 = new javax.swing.JMenu();
    jMenuItem6 = new javax.swing.JMenuItem();
    jMenuItem5 = new javax.swing.JMenuItem();
    jMenu6 = new javax.swing.JMenu();

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

    jTabbedPane1.setName(""); // NOI18N

    jPanel1.setName(""); // NOI18N

    jlabel11.setText("1st no.");

    jLabel2.setText("2nd no.");

    jLabel3.setText("Sum");

    jLabel4.setText("Multiple");

    jLabel5.setText("Dividend");

    jLabel6.setText("******");

    jLabel7.setText("*****");

    jLabel8.setText("******");

    jButton1.setText("Compute");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    }
    });

    jTextField3.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jTextField3ActionPerformed(evt);
    }
    });

    jTextField4.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jTextField4ActionPerformed(evt);
    }
    });

    jTextField5.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jTextField5ActionPerformed(evt);
    }
    });

    jTextField6.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jTextField6ActionPerformed(evt);
    }
    });

    jTextField7.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jTextField7ActionPerformed(evt);
    }
    });

    jButton2.setText("graph");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton2ActionPerformed(evt);
    }
    });

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addComponent(jLabel5)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED))
    .addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED))
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addComponent(jLabel3)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED))
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addComponent(jlabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(61, 61, 61))
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED))))
    .addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, jPanel1Layout.createSequentialGroup()
    .addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.TRAILING, false)
    .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING)
    .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE))
    .addGap(93, 93, 93))
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addComponent(jLabel7)
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, jPanel1Layout.createSequentialGroup()
    .addComponent(jLabel6)
    .addGap(107, 107, 107))
    .addComponent(jLabel8)))
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
    .addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.TRAILING, false)
    .addComponent(jTextField4)
    .addComponent(jTextField5)
    .addComponent(jTextField6)
    .addComponent(jTextField7)
    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addGap(109, 109, 109)
    .addComponent(jButton1)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 106, Short.MAX_VALUE)
    .addComponent(jButton2)))
    .addGap(76, 76, 76))
    );
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addGap(31, 31, 31)
    .addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
    .addComponent(jlabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGap(18, 18, 18)
    .addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
    .addComponent(jLabel2)
    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addGap(18, 18, 18)
    .addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
    .addComponent(jLabel6)
    .addComponent(jLabel3))
    .addGap(31, 31, 31)
    .addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
    .addComponent(jLabel4)
    .addComponent(jLabel7))
    .addGap(29, 29, 29)
    .addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
    .addComponent(jLabel8)
    .addComponent(jLabel5))
    .addGap(44, 44, 44)
    .addComponent(jButton1))
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addGap(30, 30, 30)
    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(27, 27, 27)
    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(27, 27, 27)
    .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(18, 18, 18)
    .addComponent(jButton2)))
    .addContainerGap(70, Short.MAX_VALUE))
    );

    jTabbedPane1.addTab("calc & graph", jPanel1);

    jLabel9.setIcon(new javax.swing.ImageIcon("F:\\New Document folder\\My Pictures\\New Folder (6)\\w.jpg")); // NOI18N
    jLabel9.setText("jLabel9");

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
    jPanel2Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGroup(jPanel2Layout.createSequentialGroup()
    .addGap(10, 10, 10)
    .addComponent(t, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(237, 237, 237))
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, jPanel2Layout.createSequentialGroup()
    .addContainerGap(95, Short.MAX_VALUE)
    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(124, 124, 124))
    );
    jPanel2Layout.setVerticalGroup(
    jPanel2Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGroup(jPanel2Layout.createSequentialGroup()
    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(50, 50, 50)
    .addGroup(jPanel2Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, jPanel2Layout.createSequentialGroup()
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(76, 76, 76))
    .addGroup(jPanel2Layout.createSequentialGroup()
    .addGap(87, 87, 87)
    .addComponent(t, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(42, 42, 42)))
    .addContainerGap(javax.swing.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE))
    );

    jTabbedPane1.addTab("Images", jPanel2);

    jMenu1.setText("File");

    jMenuItem1.setText("Open ");
    jMenu1.add(jMenuItem1);

    jMenuItem2.setText("Exit");
    jMenu1.add(jMenuItem2);

    jMenuBar1.add(jMenu1);

    jMenu2.setText("Edit");
    jMenuBar1.add(jMenu2);

    jMenu3.setText("File");

    jMenuItem3.setText("Open ");
    jMenu3.add(jMenuItem3);

    jMenuItem4.setText("Exit");
    jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jMenuItem4ActionPerformed(evt);
    }
    });
    jMenu3.add(jMenuItem4);

    jMenuBar2.add(jMenu3);

    jMenu4.setText("Edit");
    jMenuBar2.add(jMenu4);

    jMenu5.setText("File");

    jMenuItem6.setText("Exit");
    jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jMenuItem4ActionPerformed(evt);
    }
    });
    jMenu5.add(jMenuItem6);

    jMenuItem5.setText("Open ");
    jMenu5.add(jMenuItem5);

    jMenuBar3.add(jMenu5);

    jMenu6.setText("Edit");
    jMenuBar3.add(jMenu6);

    setJMenuBar(jMenuBar3);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(58, 58, 58)
    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 432, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(539, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(54, 54, 54)
    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 389, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(219, Short.MAX_VALUE))
    );

    jTabbedPane1.getAccessibleContext().setAccessibleN ame("tab 1");

    pack();
    }// </editor-fold>

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

    jButton1.addActionListener(new java.awt.event.ActionListener()
    { public void actionPerformed(java.awt.event.ActionEvent evt)
    { jButton1ActionPerformed(evt); }});

    //Gets how many hours worked from the text field, and then parses it to type int.
    int hu = Integer.parseInt(jTextField1.getText());
    //Gets the pay rate entered in the text field, and parses it to type double.
    double rateEntered = Double.parseDouble(jTextField2.getText());
    //Creates two variables of type double for later use.
    double regularPay = 0;
    double overTimePay = 0;
    //Simple if statement for calculations
    //// if (hu > 40) { regularPay = 40 * rateEntered;
    //// overTimePay = (hu - 40) * 1.5 * rateEntered;}
    //// else { regularPay = hu * rateEntered;
    //// overTimePay = 0.0;}
    regularPay=hu+rateEntered;
    overTimePay =hu*rateEntered;




    //Creates a variable of both types of pay combined.
    double total = hu/rateEntered;
    //Creates variables for number formatting
    NumberFormat nfRegular = NumberFormat.getCurrencyInstance(Locale.US);
    NumberFormat nfOverTime = NumberFormat.getCurrencyInstance(Locale.US);
    NumberFormat nfTotal = NumberFormat.getInstance(Locale.US);
    //Writes the totals in the correct format to the labels
    jLabel6.setText(" " + nfRegular.format(regularPay));
    jLabel7.setText(" " + nfOverTime.format(overTimePay ));
    jLabel8.setText(" " + nfTotal .format(total));
    t.setText(" " + nfTotal .format(total));

    int a = Integer.parseInt(jTextField3.getText());


    NumberFormat nfb = NumberFormat.getInstance(Locale.US);
    NumberFormat nfb1 = NumberFormat.getInstance(Locale.US);
    NumberFormat nfb2 = NumberFormat.getInstance(Locale.US);
    NumberFormat nfb3 = NumberFormat.getInstance(Locale.US);


    int b=a+1;
    int b1=a+2;
    int b2=a+3;
    int b3=a+4;


    jTextField4.setText(" " + nfb .format(b));
    jTextField5.setText(" " + nfb .format(b1));
    jTextField6.setText(" " + nfb .format(b2));
    jTextField7.setText(" " + nfb .format(b3));






    // TODO add your handling code here:
    }

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEve nt evt) {
    System.exit(1); // TODO add your handling code here:
    }

    private void jTextField3ActionPerformed(java.awt.event.ActionEv ent evt) {
    // TODO add your handling code here:
    }

    private void jTextField4ActionPerformed(java.awt.event.ActionEv ent evt) {
    // TODO add your handling code here:
    }

    private void jTextField5ActionPerformed(java.awt.event.ActionEv ent evt) {
    // TODO add your handling code here:
    }

    private void jTextField6ActionPerformed(java.awt.event.ActionEv ent evt) {
    // TODO add your handling code here:
    }

    private void jTextField7ActionPerformed(java.awt.event.ActionEv ent evt) {
    // TODO add your handling code here:
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    jButton2.addActionListener(new java.awt.event.ActionListener()
    { public void actionPerformed(java.awt.event.ActionEvent evt)
    { jButton2ActionPerformed(evt); }});

    public class da extends JPanel {
    int[] dataX = {

    0,500, 1000, 1500, 2000, 2500, 300, 350, 400, 450, 500
    };

    int dataY[] = {
    0,50, 1000, 1500, 2000, 25000,25000,1500,1000,500,0
    };

    final int PAD = 20;


    public void paintComponent(Graphics g) {

    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASIN G,

    RenderingHints.VALUE_ANTIALIAS_ON);

    int w = getWidth();
    int h = getHeight();
    // Draw ordinate.
    g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD));
    // Draw abcissa.
    g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD));
    // Draw labels.
    Font font = g2.getFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = font.getLineMetrics("0", frc);
    float sh = lm.getAscent() + lm.getDescent();
    // Ordinate label.
    String s = "Decibel Level Db";
    float sy = PAD + ((h - 2 * PAD) - s.length() * sh) / 2 + lm.getAscent();
    for (int i = 0; i < s.length(); i++) {
    String letter = String.valueOf(s.charAt(i));
    float sw = (float) font.getStringBounds(letter, frc).getWidth();
    float sx = (PAD - sw) / 2;
    g2.drawString(letter, sx, sy);
    sy += sh;
    }
    // Abcissa label.
    s = "Frequency Hz";
    sy = h - PAD + (PAD - sh) / 2 + lm.getAscent();
    float sw = (float) font.getStringBounds(s, frc).getWidth();
    float sx = (w - sw) / 2;
    g2.drawString(s, sx, sy);
    // Draw lines.
    double xInc = (double) (w - 2 * PAD) / (dataX.length - 1);
    double scale = (double) (h - 2 * PAD) / getMax();
    g2.setPaint(Color.green.darker());
    for (int i = 0; i < dataX.length - 1; i++) {
    //double x1 = PAD + i * xInc;
    double x1 = PAD + dataX[ i ];
    //double y1 = h - PAD - scale * data;
    double y1 = h - PAD - scale * dataY[i];
    //double x2 = PAD + (i + 1) * xInc;
    double x2 = PAD + dataX[i+1];
    //double y2 = h - PAD - scale * data[i + 1];
    double y2 = h - PAD - scale * dataY[i + 1];

    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    }
    // Mark data points.
    g2.setPaint(Color.red);
    for (int i = 0; i < dataX.length; i++) {
    //double x = PAD + i * xInc;
    double x = PAD + dataX[ i ];
    //double y = h - PAD - scale * data;
    double y = h - PAD - scale * dataY[i];
    g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }
    }

    private int getMax() {
    int max = -Integer.MAX_VALUE;
    for (int i = 0; i < dataX.length; i++) {
    if (dataX[i] > max) {
    max = dataX[i];
    }
    }
    return max;
    }




    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {

    //Do JFrame Stuff...
    da graff = new da ();

    // frame.add(graff);
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new da());
    f.setSize(400,400);
    f.setLocation(200,200);
    f.setVisible(true);

    //Finish Frame Stuff...

    }

    }
    // TODO add your handling code here:
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new SamplesJFrame().setVisible(true);
    }
    });
    }

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenu jMenu6;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenuBar jMenuBar3;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JLabel jlabel11;
    private javax.swing.JLabel t;
    // End of variables declaration

    }

  2. #2
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    GUI forms are tuff... I can tell you when you need to put your method to display your graph, but unfortunately I can not tell you how to get it in there...

    You want to put it inside your actionpreformed for you JButton2...

    Java Code:
         jButton2.setText("graph");
         jButton2.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
    
                    //Put your displayGraphMethod() here....
    
              }
          });
    Who Cares... As Long As It Works...

  3. #3
    Megatron's Avatar
    Megatron is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    thnx ..........

    but after modifying my code.....it is nw compiling without any error......
    but it is not showing me the graph........

    now what shall i do........

  4. #4
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    can you post your displayGraphMethod()...
    Who Cares... As Long As It Works...

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    ...and

    1) please post your code with code tags (see the forum faq), and finally, if you want to maximize the abilitiy of folks to help you,
    2) create a simple non-netbeans program that shows your gui so that the code we have to wade through is not a gabillion miles long.

    Best of luck!

  6. #6
    Megatron's Avatar
    Megatron is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    Here is the final code after modifying.......

    it compiles but still not showing me the graph...........





    Java Code:
    import java.text.NumberFormat;
    import java.util.Locale;
    import java.awt.*; 
    import java.awt.font.*; 
    import java.awt.geom.*; 
    import javax.swing.*; 
    
    
    /*
     * SamplesJFrame.java
     *
     * Created on January 16, 2015, 2:36 PM
     */
    
    
    
    /**
     *
     * @author  Megatron
     */
    public class SamplesJFrame extends javax.swing.JFrame {
        
        /** Creates new form SamplesJFrame */
        public SamplesJFrame() {
            initComponents();
        }
        
        /** 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.
         */
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            jScrollPane2 = new javax.swing.JScrollPane();
            jTabbedPane1 = new javax.swing.JTabbedPane();
            jPanel1 = new javax.swing.JPanel();
            jlabel11 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            jLabel5 = new javax.swing.JLabel();
            jLabel6 = new javax.swing.JLabel();
            jLabel7 = new javax.swing.JLabel();
            jLabel8 = new javax.swing.JLabel();
            jTextField2 = new javax.swing.JTextField();
            jTextField1 = new javax.swing.JTextField();
            jButton1 = new javax.swing.JButton();
            jTextField3 = new javax.swing.JTextField();
            jTextField4 = new javax.swing.JTextField();
            jTextField5 = new javax.swing.JTextField();
            jTextField6 = new javax.swing.JTextField();
            jTextField7 = new javax.swing.JTextField();
            jButton2 = new javax.swing.JButton();
            jPanel2 = new javax.swing.JPanel();
            t = new javax.swing.JLabel();
            jScrollPane1 = new javax.swing.JScrollPane();
            jLabel9 = new javax.swing.JLabel();
            jMenuBar1 = new javax.swing.JMenuBar();
            jMenu1 = new javax.swing.JMenu();
            jMenuItem1 = new javax.swing.JMenuItem();
            jMenuItem2 = new javax.swing.JMenuItem();
            jMenu2 = new javax.swing.JMenu();
            jMenuBar2 = new javax.swing.JMenuBar();
            jMenu3 = new javax.swing.JMenu();
            jMenuItem3 = new javax.swing.JMenuItem();
            jMenuItem4 = new javax.swing.JMenuItem();
            jMenu4 = new javax.swing.JMenu();
            jMenuBar3 = new javax.swing.JMenuBar();
            jMenu5 = new javax.swing.JMenu();
            jMenuItem6 = new javax.swing.JMenuItem();
            jMenuItem5 = new javax.swing.JMenuItem();
            jMenu6 = new javax.swing.JMenu();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            jTabbedPane1.setName(""); // NOI18N
    
            jPanel1.setName(""); // NOI18N
    
            jlabel11.setText("1st no.");
    
            jLabel2.setText("2nd no.");
    
            jLabel3.setText("Sum");
    
            jLabel4.setText("Multiple");
    
            jLabel5.setText("Dividend");
    
            jLabel6.setText("******");
    
            jLabel7.setText("*****");
    
            jLabel8.setText("******");
    
            jButton1.setText("Compute");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
    
            jTextField3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField3ActionPerformed(evt);
                }
            });
    
            jTextField4.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField4ActionPerformed(evt);
                }
            });
    
            jTextField5.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField5ActionPerformed(evt);
                }
            });
    
            jTextField6.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField6ActionPerformed(evt);
                }
            });
    
            jTextField7.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField7ActionPerformed(evt);
                }
            });
    
            jButton2.setText("graph");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel5)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jlabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(61, 61, 61))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE))
                                    .addGap(93, 93, 93))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel6)
                                        .addGap(107, 107, 107))
                                    .addComponent(jLabel8)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jTextField4)
                                .addComponent(jTextField5)
                                .addComponent(jTextField6)
                                .addComponent(jTextField7)
                                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(109, 109, 109)
                            .addComponent(jButton1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 106, Short.MAX_VALUE)
                            .addComponent(jButton2)))
                    .addGap(76, 76, 76))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(31, 31, 31)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jlabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel6)
                                .addComponent(jLabel3))
                            .addGap(31, 31, 31)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4)
                                .addComponent(jLabel7))
                            .addGap(29, 29, 29)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel8)
                                .addComponent(jLabel5))
                            .addGap(44, 44, 44)
                            .addComponent(jButton1))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(30, 30, 30)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(27, 27, 27)
                            .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(27, 27, 27)
                            .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(jButton2)))
                    .addContainerGap(70, Short.MAX_VALUE))
            );
    
            jTabbedPane1.addTab("calc & graph", jPanel1);
    
            jLabel9.setIcon(new javax.swing.ImageIcon("F:\\New Document folder\\My Pictures\\New Folder (6)\\w.jpg")); // NOI18N
            jLabel9.setText("jLabel9");
    
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(10, 10, 10)
                    .addComponent(t, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(237, 237, 237))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                    .addContainerGap(95, Short.MAX_VALUE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(124, 124, 124))
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(50, 50, 50)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(76, 76, 76))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGap(87, 87, 87)
                            .addComponent(t, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(42, 42, 42)))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
    
            jTabbedPane1.addTab("Images", jPanel2);
    
            jMenu1.setText("File");
    
            jMenuItem1.setText("Open ");
            jMenu1.add(jMenuItem1);
    
            jMenuItem2.setText("Exit");
            jMenu1.add(jMenuItem2);
    
            jMenuBar1.add(jMenu1);
    
            jMenu2.setText("Edit");
            jMenuBar1.add(jMenu2);
    
            jMenu3.setText("File");
    
            jMenuItem3.setText("Open ");
            jMenu3.add(jMenuItem3);
    
            jMenuItem4.setText("Exit");
            jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jMenuItem4ActionPerformed(evt);
                }
            });
            jMenu3.add(jMenuItem4);
    
            jMenuBar2.add(jMenu3);
    
            jMenu4.setText("Edit");
            jMenuBar2.add(jMenu4);
    
            jMenu5.setText("File");
    
            jMenuItem6.setText("Exit");
            jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jMenuItem4ActionPerformed(evt);
                }
            });
            jMenu5.add(jMenuItem6);
    
            jMenuItem5.setText("Open ");
            jMenu5.add(jMenuItem5);
    
            jMenuBar3.add(jMenu5);
    
            jMenu6.setText("Edit");
            jMenuBar3.add(jMenu6);
    
            setJMenuBar(jMenuBar3);
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(58, 58, 58)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 432, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(539, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(54, 54, 54)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 389, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(219, Short.MAX_VALUE))
            );
    
            jTabbedPane1.getAccessibleContext().setAccessibleName("tab 1");
    
            pack();
        }// </editor-fold>                        
    
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    
           jButton1.addActionListener(new java.awt.event.ActionListener() 
           {    public void actionPerformed(java.awt.event.ActionEvent evt) 
                {        jButton1ActionPerformed(evt);    }}); 
            
            //Gets how many hours worked from the text field, and then parses it to type int.
           int hu = Integer.parseInt(jTextField1.getText());
           //Gets the pay rate entered in the text field, and parses it to type double.
           double rateEntered = Double.parseDouble(jTextField2.getText());
           //Creates two variables of type double for later use.
           double regularPay = 0;
           double overTimePay = 0;
           //Simple if statement for calculations
    ////       if (hu > 40) {    regularPay = 40 * rateEntered;   
    ////       overTimePay = (hu - 40) * 1.5 * rateEntered;} 
    ////       else {      regularPay = hu * rateEntered;     
    ////       overTimePay = 0.0;}
           regularPay=hu+rateEntered;
           overTimePay =hu*rateEntered;
           
           
           
           
           //Creates a variable of both types of pay combined.
           double total = hu/rateEntered;
           //Creates variables for number formatting
           NumberFormat nfRegular  = NumberFormat.getCurrencyInstance(Locale.US);
           NumberFormat nfOverTime  = NumberFormat.getCurrencyInstance(Locale.US);
           NumberFormat nfTotal  = NumberFormat.getInstance(Locale.US);
           //Writes the totals in the correct format to the labels
           jLabel6.setText(" " + nfRegular.format(regularPay));
           jLabel7.setText(" " + nfOverTime.format(overTimePay ));
           jLabel8.setText(" " + nfTotal .format(total)); 
           t.setText(" " + nfTotal .format(total)); 
           
           int a = Integer.parseInt(jTextField3.getText());
           
           
           NumberFormat nfb  = NumberFormat.getInstance(Locale.US);
           NumberFormat nfb1  = NumberFormat.getInstance(Locale.US);
           NumberFormat nfb2  = NumberFormat.getInstance(Locale.US);
           NumberFormat nfb3  = NumberFormat.getInstance(Locale.US);
           
           
           int b=a+1;
           int b1=a+2;
           int b2=a+3;
           int b3=a+4;
           
           
          jTextField4.setText(" " + nfb .format(b));
          jTextField5.setText(" " + nfb .format(b1));
          jTextField6.setText(" " + nfb .format(b2));
          jTextField7.setText(" " + nfb .format(b3));
          
          
    
    
           
           
           // TODO add your handling code here:
        }                                        
    
        private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
           System.exit(1);        // TODO add your handling code here:
        }                                          
    
        private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
        }                                           
    
        private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
        }                                           
    
        private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
        }                                           
    
        private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
        }                                           
    
        private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
        }                                           
    
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
          jButton2.setText("graph");
         jButton2.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
    
                    //Put your displayGraphMethod() here....
    
              }
          });
                
           class da extends JPanel {       
    int[] dataX = {
     
    0,500, 1000, 1500, 2000, 2500, 300, 350, 400, 450, 500
    };
     
    int dataY[] = {
    0,50, 1000, 1500, 2000, 25000,25000,1500,1000,500,0
    };
     
    final int PAD = 20; 
    
    
    public void paintComponent(Graphics g) { 
     
    super.paintComponent(g); 
     
    Graphics2D g2 = (Graphics2D) g; 
     
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
     
    RenderingHints.VALUE_ANTIALIAS_ON); 
     
    int w = getWidth(); 
    int h = getHeight(); 
    // Draw ordinate. 
    g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD)); 
    // Draw abcissa. 
    g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD)); 
    // Draw labels. 
    Font font = g2.getFont(); 
    FontRenderContext frc = g2.getFontRenderContext(); 
    LineMetrics lm = font.getLineMetrics("0", frc); 
    float sh = lm.getAscent() + lm.getDescent(); 
    // Ordinate label. 
    String s = "Decibel Level Db"; 
    float sy = PAD + ((h - 2 * PAD) - s.length() * sh) / 2 + lm.getAscent(); 
    for (int i = 0; i < s.length(); i++) { 
    String letter = String.valueOf(s.charAt(i)); 
    float sw = (float) font.getStringBounds(letter, frc).getWidth(); 
    float sx = (PAD - sw) / 2; 
    g2.drawString(letter, sx, sy); 
    sy += sh; 
    } 
    // Abcissa label. 
    s = "Frequency Hz"; 
    sy = h - PAD + (PAD - sh) / 2 + lm.getAscent(); 
    float sw = (float) font.getStringBounds(s, frc).getWidth(); 
    float sx = (w - sw) / 2; 
    g2.drawString(s, sx, sy); 
    // Draw lines. 
    double xInc = (double) (w - 2 * PAD) / (dataX.length - 1); 
    double scale = (double) (h - 2 * PAD) / getMax(); 
    g2.setPaint(Color.green.darker()); 
    for (int i = 0; i < dataX.length - 1; i++) { 
    //double x1 = PAD + i * xInc;
    double x1 = PAD + dataX[ i ];
    //double y1 = h - PAD - scale * data; 
    double y1 = h - PAD - scale * dataY[i]; 
    //double x2 = PAD + (i + 1) * xInc; 
    double x2 = PAD + dataX[i+1];
    //double y2 = h - PAD - scale * data[i + 1]; 
    double y2 = h - PAD - scale * dataY[i + 1];
     
    g2.draw(new Line2D.Double(x1, y1, x2, y2)); 
    } 
    // Mark data points. 
    g2.setPaint(Color.red); 
    for (int i = 0; i < dataX.length; i++) { 
    //double x = PAD + i * xInc; 
    double x = PAD + dataX[ i ];
    //double y = h - PAD - scale * data; 
    double y = h - PAD - scale * dataY[i]; 
    g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); 
    } 
    } 
     
    private int getMax() { 
    int max = -Integer.MAX_VALUE; 
    for (int i = 0; i < dataX.length; i++) { 
    if (dataX[i] > max) { 
    max = dataX[i]; 
    } 
    } 
    return max; 
    } 
    
    
    
    
        /**
         * @param args the command line arguments
         */
         void main(String[] args) {
            
             //Do JFrame Stuff...
             da  graff = new da ();
    
    //         frame.add(graff);
             JFrame f = new JFrame();
             f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             f.add(new da());
             f.setSize(400,400);
             f.setLocation(200,200);
             f.setVisible(true);
                      
             //Finish Frame Stuff...
     
        }
    
    }
     // TODO add your handling code here:
        }                                        
        
        /**
         * @param args the command line arguments
         */
       public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new SamplesJFrame().setVisible(true);
                }
            });
        }
            
        // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JMenu jMenu1;
        private javax.swing.JMenu jMenu2;
        private javax.swing.JMenu jMenu3;
        private javax.swing.JMenu jMenu4;
        private javax.swing.JMenu jMenu5;
        private javax.swing.JMenu jMenu6;
        private javax.swing.JMenuBar jMenuBar1;
        private javax.swing.JMenuBar jMenuBar2;
        private javax.swing.JMenuBar jMenuBar3;
        private javax.swing.JMenuItem jMenuItem1;
        private javax.swing.JMenuItem jMenuItem2;
        private javax.swing.JMenuItem jMenuItem3;
        private javax.swing.JMenuItem jMenuItem4;
        private javax.swing.JMenuItem jMenuItem5;
        private javax.swing.JMenuItem jMenuItem6;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JTabbedPane jTabbedPane1;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField jTextField2;
        private javax.swing.JTextField jTextField3;
        private javax.swing.JTextField jTextField4;
        private javax.swing.JTextField jTextField5;
        private javax.swing.JTextField jTextField6;
        private javax.swing.JTextField jTextField7;
        private javax.swing.JLabel jlabel11;
        private javax.swing.JLabel t;
        // End of variables declaration                   
        
        }

  7. #7
    Megatron's Avatar
    Megatron is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    For markw8500 ----->

    This is only the portion under a "button" to generate the graph..........


    Java Code:
     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
          jButton2.setText("graph");
         jButton2.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
    
                    //Put your displayGraphMethod() here....
    
              }
          });
                
           class da extends JPanel {       
    int[] dataX = {
     
    0,500, 1000, 1500, 2000, 2500, 300, 350, 400, 450, 500
    };
     
    int dataY[] = {
    0,50, 1000, 1500, 2000, 25000,25000,1500,1000,500,0
    };
     
    final int PAD = 20; 
    
    
    public void paintComponent(Graphics g) { 
     
    super.paintComponent(g); 
     
    Graphics2D g2 = (Graphics2D) g; 
     
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
     
    RenderingHints.VALUE_ANTIALIAS_ON); 
     
    int w = getWidth(); 
    int h = getHeight(); 
    // Draw ordinate. 
    g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD)); 
    // Draw abcissa. 
    g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD)); 
    // Draw labels. 
    Font font = g2.getFont(); 
    FontRenderContext frc = g2.getFontRenderContext(); 
    LineMetrics lm = font.getLineMetrics("0", frc); 
    float sh = lm.getAscent() + lm.getDescent(); 
    // Ordinate label. 
    String s = "Decibel Level Db"; 
    float sy = PAD + ((h - 2 * PAD) - s.length() * sh) / 2 + lm.getAscent(); 
    for (int i = 0; i < s.length(); i++) { 
    String letter = String.valueOf(s.charAt(i)); 
    float sw = (float) font.getStringBounds(letter, frc).getWidth(); 
    float sx = (PAD - sw) / 2; 
    g2.drawString(letter, sx, sy); 
    sy += sh; 
    } 
    // Abcissa label. 
    s = "Frequency Hz"; 
    sy = h - PAD + (PAD - sh) / 2 + lm.getAscent(); 
    float sw = (float) font.getStringBounds(s, frc).getWidth(); 
    float sx = (w - sw) / 2; 
    g2.drawString(s, sx, sy); 
    // Draw lines. 
    double xInc = (double) (w - 2 * PAD) / (dataX.length - 1); 
    double scale = (double) (h - 2 * PAD) / getMax(); 
    g2.setPaint(Color.green.darker()); 
    for (int i = 0; i < dataX.length - 1; i++) { 
    //double x1 = PAD + i * xInc;
    double x1 = PAD + dataX[ i ];
    //double y1 = h - PAD - scale * data; 
    double y1 = h - PAD - scale * dataY[i]; 
    //double x2 = PAD + (i + 1) * xInc; 
    double x2 = PAD + dataX[i+1];
    //double y2 = h - PAD - scale * data[i + 1]; 
    double y2 = h - PAD - scale * dataY[i + 1];
     
    g2.draw(new Line2D.Double(x1, y1, x2, y2)); 
    } 
    // Mark data points. 
    g2.setPaint(Color.red); 
    for (int i = 0; i < dataX.length; i++) { 
    //double x = PAD + i * xInc; 
    double x = PAD + dataX[ i ];
    //double y = h - PAD - scale * data; 
    double y = h - PAD - scale * dataY[i]; 
    g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); 
    } 
    } 
     
    private int getMax() { 
    int max = -Integer.MAX_VALUE; 
    for (int i = 0; i < dataX.length; i++) { 
    if (dataX[i] > max) { 
    max = dataX[i]; 
    } 
    } 
    return max; 
    } 
    
    
    
    
        /**
         * @param args the command line arguments
         */
         void main(String[] args) {
            
             //Do JFrame Stuff...
             da  graff = new da ();
    
    //         frame.add(graff);
             JFrame f = new JFrame();
             f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             f.add(new da());
             f.setSize(400,400);
             f.setLocation(200,200);
             f.setVisible(true);
                      
             //Finish Frame Stuff...
     
        }
    
    }
     // TODO add your handling code here:
        }

  8. #8
    Megatron's Avatar
    Megatron is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Question

    Quote Originally Posted by Fubarable View Post
    ...and

    1) please post your code with code tags (see the forum faq), and finally, if you want to maximize the abilitiy of folks to help you,
    2) create a simple non-netbeans program that shows your gui so that the code we have to wade through is not a gabillion miles long.

    Best of luck!

    Thnx for ur suggestion..........

    I will try to follow that in future..........:)

  9. #9
    Megatron's Avatar
    Megatron is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    anyone out there with GUI knowledge...........plz help me........

    thnx.......

  10. #10
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    JImage(is this even an object?) seems like it would be easy to attach to a JPanel or Composite or something. I'm guessing you have an image of a graph already and you just need it on there? Or that when the user clicks the button it calculates and draws a graph? You could probably accomplish the latter by using drawLine with angles and such but I would only reccomend that as a VERY last option because it seems overly complicated.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  11. #11
    Megatron's Avatar
    Megatron is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Question

    Quote Originally Posted by xcallmejudasx View Post
    JImage(is this even an object?) seems like it would be easy to attach to a JPanel or Composite or something. I'm guessing you have an image of a graph already and you just need it on there? Or that when the user clicks the button it calculates and draws a graph? You could probably accomplish the latter by using drawLine with angles and such but I would only reccomend that as a VERY last option because it seems overly complicated.
    I ve 2 sets of variables and when the button is pressed then the graph should be shown...........

    If i do this seperately as one program then it runs.....

    but when i inserted it under the button then it is not working..... :(:(

  12. #12
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    In your initComponents() method you have this code:

    Java Code:
             jButton2.addActionListener(new java.awt.event.ActionListener() {
    
                public void actionPerformed(java.awt.event.ActionEvent evt) {
    
    
                    jButton2ActionPerformed(evt);
                }
            });
    Now what this does is add the actionListener to your graph button... Typically in a non netBeans form, you would add your code in the actionPerformed method... But in your case netBeans will not let you... Instead netBeans creates another method called jButton2ActionPerformed and calls it when the event is fired... So now what you want to do is find the jButton2ActionPerformed(ActionEvent evt) method and add the code to set the visiibility JTabbedPane1 to false and revalidate and repaint...

    Now I also noticed that you added my sample code to your form... You don't want to do that... So make sure you remove it...
    Who Cares... As Long As It Works...

  13. #13
    Megatron's Avatar
    Megatron is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    Hey markw8500 thnx..........

    THNX a Trillion times................... :)

    At last..........it worked..............

    Thnx 2 all of those people who helped me with their prescious sugesstions........... :)
    Last edited by Megatron; 04-23-2009 at 12:10 AM.

  14. #14
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    Any Time...
    Who Cares... As Long As It Works...

  15. #15
    Megatron's Avatar
    Megatron is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    hey markw8500.............

    Could u tell me how I can mark the axis....

    like X: 01 02 03 04 ..................
    Y: 01 02 03 04 ............

    so when the graph will be plot then at the same time both the axis will show their own axis value.............

    another thing.....is it possible 2 write a code that would adjust the scale of the plot on its own ?..........

    Any suggestion or help from anyone out there with GUI knowledge will be appreciable........

    Thnx.................

  16. #16
    corlettk is offline Member
    Join Date
    Apr 2009
    Location
    Brisbane
    Posts
    86
    Rep Power
    0

    Default

    After reading through this thread I recommend that you all get your period keys attended to, posthaste.

    ............................... Oh FFS ...................................

    I've been know to use three in a row... but filling the ether with periods? Period!

  17. #17
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    You already have the tools to do this... Try it out and if you get stuck lte me know...
    Last edited by markw8500; 04-24-2009 at 04:14 PM.
    Who Cares... As Long As It Works...

  18. #18
    Megatron's Avatar
    Megatron is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    nope................cant figure it out.............

  19. #19
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    Hmmm... I see...

    Well... Everything that you need to do will take place here:

    Java Code:
    public void paintComponent(Graphics g) { 
     
    super.paintComponent(g); 
     
    Graphics2D g2 = (Graphics2D) g; 
     
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
     
    RenderingHints.VALUE_ANTIALIAS_ON); 
     
    int w = getWidth(); 
    int h = getHeight(); 
    // Draw ordinate. 
    g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD)); 
    // Draw abcissa. 
    g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD)); 
    // Draw labels. 
    Font font = g2.getFont(); 
    FontRenderContext frc = g2.getFontRenderContext(); 
    LineMetrics lm = font.getLineMetrics("0", frc); 
    float sh = lm.getAscent() + lm.getDescent(); 
    // Ordinate label. 
    String s = "Decibel Level Db"; 
    float sy = PAD + ((h - 2 * PAD) - s.length() * sh) / 2 + lm.getAscent(); 
    for (int i = 0; i < s.length(); i++) { 
    String letter = String.valueOf(s.charAt(i)); 
    float sw = (float) font.getStringBounds(letter, frc).getWidth(); 
    float sx = (PAD - sw) / 2; 
    g2.drawString(letter, sx, sy); 
    sy += sh; 
    } 
    // Abcissa label. 
    s = "Frequency Hz"; 
    sy = h - PAD + (PAD - sh) / 2 + lm.getAscent(); 
    float sw = (float) font.getStringBounds(s, frc).getWidth(); 
    float sx = (w - sw) / 2; 
    g2.drawString(s, sx, sy); 
    // Draw lines. 
    double xInc = (double) (w - 2 * PAD) / (dataX.length - 1); 
    double scale = (double) (h - 2 * PAD) / getMax(); 
    g2.setPaint(Color.green.darker()); 
    for (int i = 0; i < dataX.length - 1; i++) { 
    //double x1 = PAD + i * xInc;
    double x1 = PAD + dataX[ i ];
    //double y1 = h - PAD - scale * data; 
    double y1 = h - PAD - scale * dataY[i]; 
    //double x2 = PAD + (i + 1) * xInc; 
    double x2 = PAD + dataX[i+1];
    //double y2 = h - PAD - scale * data[i + 1]; 
    double y2 = h - PAD - scale * dataY[i + 1];
     
    g2.draw(new Line2D.Double(x1, y1, x2, y2)); 
    } 
    // Mark data points. 
    g2.setPaint(Color.red); 
    for (int i = 0; i < dataX.length; i++) { 
    //double x = PAD + i * xInc; 
    double x = PAD + dataX[ i ];
    //double y = h - PAD - scale * data; 
    double y = h - PAD - scale * dataY[i]; 
    g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); 
    } 
    }
    Become one with Graphics2D and Paint... And answers you will find...
    Who Cares... As Long As It Works...

  20. #20
    Megatron's Avatar
    Megatron is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    could u give me the modified code showing the use of axis value......?
    I tried fr several hours.........but mine not workin.............:(

Similar Threads

  1. Help! Plotting a function
    By cvubando in forum New To Java
    Replies: 14
    Last Post: 02-20-2009, 08:34 AM
  2. Problems with graph plotting.
    By oveeye in forum AWT / Swing
    Replies: 2
    Last Post: 02-05-2009, 09:20 AM
  3. graph plotting
    By sirine in forum New To Java
    Replies: 5
    Last Post: 01-25-2009, 04:34 PM
  4. Replies: 5
    Last Post: 08-02-2008, 09:05 PM
  5. line plotting math
    By Ace_Of_John in forum Java 2D
    Replies: 1
    Last Post: 01-19-2008, 11:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •