Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
|
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 18th, 2006, 12:17 PM
Registered User
 
Join Date: Jun 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems Getting Values

Hi to all, i'm new :)
I want to create a JFrame that has 2 JLabel, 2 JTextField and 1 JButton.
In this JFrame i want to get the values that will be insert in the Jtexfield, when the 2 values are write i want to press a button (lest say a "OK" button) that led to an actionperformed that will save the 2 values in 2 int (lest say int a; int b;). I already have that done, buy my problem is that i want to use that those 2 values to draw a grid or a rectangule. I have to create a paint funcion to begin use the drawline command. But i don't know how to use the 2 values that i already have (int a,b) to draw something. I mean, i don't know how to get those values in my paint funcion. Here's what i have done.

import java.awt.Graphics;
import java.awt.Color;
public class Ventana3 extends javax.swing.JFrame {
 public int a;
 public int b;
   public Ventana3() {
        initComponents();
    }

    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
        jFrame1 = new javax.swing.JFrame();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();

        org.jdesktop.layout.GroupLayout jFrame1Layout = new org.jdesktop.layout.GroupLayout(jFrame1.getContent Pane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(org.jdesktop.lay out.GroupLayout.LEADING)
            .add(0, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(org.jdesktop.lay out.GroupLayout.LEADING)
            .add(0, 300, Short.MAX_VALUE)
        );

        getContentPane().setLayout(null);

        setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
        jLabel1.setText("Ancho");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(20, 20, 34, 14);

        jLabel2.setText("Alto");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(20, 50, 34, 14);

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

        getContentPane().add(jButton1);
        jButton1.setBounds(150, 80, 47, 23);

        getContentPane().add(jTextField1);
        jTextField1.setBounds(80, 20, 64, 19);

        getContentPane().add(jTextField2);
        jTextField2.setBounds(80, 50, 64, 19);

        jMenu1.setText("Menu");
        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

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

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//int x, y;
a=Integer.parseInt(jTextField1.getText());
b=Integer.parseInt(jTextField2.getText());
//paint(a,b);
/*Here's the actionperformed button that i was talking about, my problem is that i want to use the x,y values in the funcion below*/
    }

   public void paint(Graphics g)
    {
        int x, y;
        //int w = this.getWidth();
        //int h = this.getHeight();
        y = 10;
        while (y <= a)
        {
            g.drawLine(10, y, a, y);
            y = y + 25;
        }
        x = 10;
        while (x <= b)
        {
            g.drawLine(x, 10, x, b);
            x = x + 25;
        }
    }

     public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Ventana3().setVisible(true);
            }
        });
    }

    private javax.swing.JButton jButton1;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;

}

Thanks for the help.







Similar Threads
Thread Thread Starter Forum Replies Last Post
get the values of form field values crmpicco Perl 2 March 16th, 2007 10:57 AM
loop values and text box values move mateenmohd Classic ASP Basics 2 April 5th, 2005 11:33 PM
validate.asp problems and logon.asp problems p2ptolu Classic ASP Databases 0 February 16th, 2005 02:34 PM
why don't i see all my values? monstermash Classic ASP Basics 6 July 18th, 2003 11:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.