Advertising (This ad goes away for registered users. You can Login or Register)

Java - Creating Textfield

Discuss about your favorite (gaming...or not) devices here. The most popular ones will end up getting their own categories
Programming discussions for your favorite Device
Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
Locked
KaptainBio
Posts: 30
Joined: Sun Jul 07, 2013 11:02 am
Location: C:\Music\Metal

Java - Creating Textfield

Post by KaptainBio »

Heya Com!
I am back and have one or more question(s).

I hope that you can help me :)

Ok, first i want you to introduce into my problem ^^

What I want:
I want to program a program which can work with a Matrix.
That means it should be able to mulitplicate a 3*3 Matrix with a 3*3 Matrix and so on.

What I have done:
[spoiler]

Code: Select all

package AWT_Programm;
import java.awt.*;
import java.awt.event.*;

public class GUI_Beispiel extends Frame {	
	
	//Enable closing of a Window
		class CloseWindow extends WindowAdapter {
			public void windowClosing (WindowEvent e){
				System.exit(0);
			}
		}
		
	GUI_Beispiel(String title){
		super(title);
		
		Button a11 = new Button ("a11");
		Button a12 = new Button ("a12");
		Button a13 = new Button ("a13");
		Button a21 = new Button ("a21");
		Button a22 = new Button ("a22");
		Button a23 = new Button ("a23");
		Button a31 = new Button ("a31");
		Button a32 = new Button ("a32");
		Button a33 = new Button ("a33");
		
		setLayout(new GridLayout(3,3));
		
		add(a11,0-0);
		add(a12,0-1);
		add(a13);
		add(a21);
		add(a22);
		add(a23);
		add(a31);
		add(a32);
		add(a33);
	}
	
public static void main(String[] args) {
	GUI_Beispiel fenster = new GUI_Beispiel("Matrix Rechner");
	
	
	fenster.pack();
	fenster.setVisible(true);
	
		}
	}

[/spoiler]

What I want (part 2)
I want to make out of the Buttons Elements, where i can type a tnumber in it, so that i can give him a second matrix to do his job .

My question:
How I gonna do it?
Which event do I have to use?
Key or Text Listener?
(I think Text Listener but I am not sure about it)

Gz Bio
Have a nice day!
Advertising
Acid_Snake
Retired Mod
Posts: 3100
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: Java - Creating Textfield

Post by Acid_Snake »

I could probably help you out if I didn't understand anything about your problem. Improve a bit on your english to make it easier for me (and others) to understand in order to get better quality help.
Advertising
Xian Nox
Retired Mod
Posts: 2744
Joined: Fri Nov 05, 2010 5:27 pm
Location: Over the hills and far away

Re: Java - Creating Textfield

Post by Xian Nox »

From a user perspective, you don't change the text of a button. No person will expect buttons to work that way.
If you *really* want to only have buttons for input, why don't you set up an ActionListener that will change the value of the button label? Like

Code: Select all

 JButton button = new JButton("0");
button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        button.setText(Integer.parseInt(button.getText()) + 1);
    }
});
Or better yet, implementing an ActionListener in a nested class, and having it take a button as a parameter in the constructor.
This should (hopefully, in case I didn't royally screw up) increment the value of the label as you press the button.

You can also use some text fields or better yet spinners to get input for the two matrices, and then a number of labels for the output. What I see so far is 9 buttons; a 3*3 matrix should have 9 elements, so I don't get how you're supposed to get your input really.

Hope this helps.
Locked

Return to “Programming and Security”