Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 18th, 2006, 12:17 PM
Registered User
Join Date: Jun 2006
Location: , , .
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() {

    // <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());
            jFrame1Layout.createParallelGroup(org.jdesktop.lay out.GroupLayout.LEADING)
            .add(0, 400, Short.MAX_VALUE)
            jFrame1Layout.createParallelGroup(org.jdesktop.lay out.GroupLayout.LEADING)
            .add(0, 300, Short.MAX_VALUE)


        setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
        jLabel1.setBounds(20, 20, 34, 14);

        jLabel2.setBounds(20, 50, 34, 14);

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

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

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

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



    }// </editor-fold>

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//int x, y;
/*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.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 06:11 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.