How can i transfer the data to other txtfield when click submit

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 4829 Views - Last Post: 25 September 2012 - 06:13 PM Rate Topic: -----

#1 keziahcook  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 22-September 12

How can i transfer the data to other txtfield when click submit

Posted 22 September 2012 - 11:34 PM

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


class newframe extends JFrame {

public static void main(String[] args) {
newframe frameTabel = new newframe();
//frameTabel.setLayout(new GridLayout(1,2));
}

JLabel emp1 = new JLabel("Employee ID:");
JLabel emp2 = new JLabel("Employee Name:");
JLabel emp3 = new JLabel("Employee Sales:");
JTextField id = new JTextField(15);
JTextField name = new JTextField(15);
JTextField sales = new JTextField(15);
JPanel panel = new JPanel();
JLabel emp4 = new JLabel("Employee ID");
JLabel emp5 = new JLabel("Employee Name");
JLabel emp6 = new JLabel("Employee Sales");
JButton bt1 = new JButton("SUBMIT");
JButton bt2 = new JButton("MAX");
JButton bt3 = new JButton("MIN");
JButton bt4 = new JButton("EXIT");

JTextField txt1 = new JTextField();
JTextField txt2 = new JTextField();
JTextField txt3 = new JTextField();
JTextField txt4 = new JTextField();
JTextField txt5 = new JTextField();
JTextField txt6 = new JTextField();
JTextField txt7 = new JTextField();
JTextField txt8 = new JTextField();
JTextField txt9 = new JTextField();
JTextField txt10 = new JTextField();
JTextField txt11 = new JTextField();
JTextField txt12 = new JTextField();
JTextField txt13 = new JTextField();
JTextField txt14 = new JTextField();
JTextField txt15 = new JTextField();

newframe(){
super("Monthly Sales");
setSize(350,400);
setLocation(500,280);
panel.setLayout (null); 

bt1.setBounds(110,100,80,30);
bt2.setBounds(10,320,80,30);
bt3.setBounds(115,320,80,30);
bt4.setBounds(220,320,80,30);

emp1.setBounds(10,20,150,30);
emp2.setBounds(10,40,150,30);
emp3.setBounds(10,60,150,30);
emp4.setBounds(10,150,150,30);
emp5.setBounds(105,150,150,30);
emp6.setBounds(220,150,150,30);
id.setBounds(110,25,150,20);
name.setBounds(110,45,150,20);
sales.setBounds(110,65,150,20);
//l1.setBounds(10,180,150,20);

txt1.setBounds(10,175,75,20);
txt2.setBounds(10,200,75,20);
txt3.setBounds(10,225,75,20);
txt4.setBounds(10,250,75,20);
txt5.setBounds(10,275,75,20);
txt6.setBounds(100,175,110,20);
txt7.setBounds(100,200,110,20);
txt8.setBounds(100,225,110,20);
txt9.setBounds(100,250,110,20);
txt10.setBounds(100,275,110,20);
txt11.setBounds(220,175,90,20);
txt12.setBounds(220,200,90,20);
txt13.setBounds(220,225,90,20);
txt14.setBounds(220,250,90,20);
txt15.setBounds(220,275,90,20);

panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Monthly Sale"));
panel.add(emp1);
panel.add(emp2);
panel.add(emp3);
panel.add(emp4);
panel.add(emp5);
panel.add(emp6);

panel.add(bt1);
panel.add(bt2);
panel.add(bt3);
panel.add(bt4);

panel.add(id);
panel.add(name);
panel.add(sales);

panel.add(txt1);
panel.add(txt2);
panel.add(txt3);
panel.add(txt4);
panel.add(txt5);
panel.add(txt6);
panel.add(txt7);
panel.add(txt8);
panel.add(txt9);
panel.add(txt10);
panel.add(txt11);
panel.add(txt12);
panel.add(txt13);
panel.add(txt14);
panel.add(txt15);

getContentPane().add(panel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}

}


This post has been edited by pbl: 23 September 2012 - 10:00 AM
Reason for edit:: Duplicated code removed


Is This A Good Question/Topic? 0
  • +

Replies To: How can i transfer the data to other txtfield when click submit

#2 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 874
  • View blog
  • Posts: 2,706
  • Joined: 29-July 11

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 12:24 AM

textField2.setText(textField1.getText());



Just copy the text from one field to another in your button's actionPerformed().
Was This Post Helpful? 0
  • +
  • -

#3 keziahcook  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 22-September 12

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 07:18 AM

how will i put that to may code..?
sorry sir Im just a newbie in java
Was This Post Helpful? 0
  • +
  • -

#4 keziahcook  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 22-September 12

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 07:38 AM

Is this right?



bt1.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
txt2.setText(txt1.getText());

Was This Post Helpful? 0
  • +
  • -

#5 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 874
  • View blog
  • Posts: 2,706
  • Joined: 29-July 11

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 07:46 AM

Looks good.
Was This Post Helpful? 0
  • +
  • -

#6 keziahcook  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 22-September 12

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 08:00 AM

but is not working T_T

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


class newframe extends JFrame{

public static void main(String[] args) {
newframe frameTabel = new newframe();
//frameTabel.setLayout(new GridLayout(1,2));
}

JLabel emp1 = new JLabel("Employee ID:");
JLabel emp2 = new JLabel("Employee Name:");
JLabel emp3 = new JLabel("Employee Sales:");
JTextField id = new JTextField(15);
JTextField name = new JTextField(15);
JTextField sales = new JTextField(15);
JPanel panel = new JPanel();
JLabel emp4 = new JLabel("Employee ID");
JLabel emp5 = new JLabel("Employee Name");
JLabel emp6 = new JLabel("Employee Sales");
JButton bt1 = new JButton("SUBMIT");
JButton bt2 = new JButton("MAX");
JButton bt3 = new JButton("MIN");
JButton bt4 = new JButton("EXIT");

JTextField txt1 = new JTextField();
JTextField txt2 = new JTextField();
JTextField txt3 = new JTextField();
JTextField txt4 = new JTextField();
JTextField txt5 = new JTextField();
JTextField txt6 = new JTextField();
JTextField txt7 = new JTextField();
JTextField txt8 = new JTextField();
JTextField txt9 = new JTextField();
JTextField txt10 = new JTextField();
JTextField txt11 = new JTextField();
JTextField txt12 = new JTextField();
JTextField txt13 = new JTextField();
JTextField txt14 = new JTextField();
JTextField txt15 = new JTextField();

newframe(){
super("Monthly Sales");
setSize(350,400);
setLocation(500,280);
panel.setLayout (null); 

bt1.setBounds(110,100,80,30);
bt2.setBounds(10,320,80,30);
bt3.setBounds(115,320,80,30);
bt4.setBounds(220,320,80,30);

emp1.setBounds(10,20,150,30);
emp2.setBounds(10,40,150,30);
emp3.setBounds(10,60,150,30);
emp4.setBounds(10,150,150,30);
emp5.setBounds(105,150,150,30);
emp6.setBounds(220,150,150,30);
id.setBounds(110,25,150,20);
name.setBounds(110,45,150,20);
sales.setBounds(110,65,150,20);
//l1.setBounds(10,180,150,20);

txt1.setBounds(10,175,75,20);
txt2.setBounds(10,200,75,20);
txt3.setBounds(10,225,75,20);
txt4.setBounds(10,250,75,20);
txt5.setBounds(10,275,75,20);
txt6.setBounds(100,175,110,20);
txt7.setBounds(100,200,110,20);
txt8.setBounds(100,225,110,20);
txt9.setBounds(100,250,110,20);
txt10.setBounds(100,275,110,20);
txt11.setBounds(220,175,90,20);
txt12.setBounds(220,200,90,20);
txt13.setBounds(220,225,90,20);
txt14.setBounds(220,250,90,20);
txt15.setBounds(220,275,90,20);

panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Monthly Sale"));
panel.add(emp1);
panel.add(emp2);
panel.add(emp3);
panel.add(emp4);
panel.add(emp5);
panel.add(emp6);

panel.add(bt1);
panel.add(bt2);
panel.add(bt3);
panel.add(bt4);

panel.add(id);
panel.add(name);
panel.add(sales);

panel.add(txt1);
panel.add(txt2);
panel.add(txt3);
panel.add(txt4);
panel.add(txt5);
panel.add(txt6);
panel.add(txt7);
panel.add(txt8);
panel.add(txt9);
panel.add(txt10);
panel.add(txt11);
panel.add(txt12);
panel.add(txt13);
panel.add(txt14);
panel.add(txt15);

bt1.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
txt2.setText(txt1.getText());



}
});
getContentPane().add(panel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}


Was This Post Helpful? 0
  • +
  • -

#7 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 874
  • View blog
  • Posts: 2,706
  • Joined: 29-July 11

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 08:51 AM

It works just fine. Fill in the extfield under Employee ID, then click submit. You'll see that it copies the text to the field below. Now, based on that, you can move those top three fields to the bottom. Think about it.

This post has been edited by farrell2k: 23 September 2012 - 08:52 AM

Was This Post Helpful? 0
  • +
  • -

#8 keziahcook  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 22-September 12

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 09:09 AM

Attached Image

Thanks sir..
Now..how can i repeat it to the other textfields?
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 10:06 AM

You will need an array of JTextField to do that.
You will need an index to know what is the last row you filed and add 1 to it each time you click the JButton

Also, JTextField are read/write fields. If you want just to display data, better to use JLabel rather than JTextField.
You should also learn how to use one of the many AWT Layout. No need to setBounds() all the fields by hand, what will you do when you'll have 300 output fields ?
Was This Post Helpful? 0
  • +
  • -

#10 keziahcook  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 22-September 12

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 10:20 AM

sir
Do you have some tutorials so I can learn more about Java?
Was This Post Helpful? 0
  • +
  • -

#11 keziahcook  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 22-September 12

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 10:27 AM

And sir what else can I use except setBounds()
align my fields?
Was This Post Helpful? 0
  • +
  • -

#12 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 10:49 AM

Here is a skeleton you should be able to start with

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


class newframe extends JFrame{

	JButton submit = new JButton("Submit");
	
	public static void main(String[] args) {
		newframe frameTabel = new newframe();
		//frameTabel.setLayout(new GridLayout(1,2));
	}

	JTextField id = new JTextField(15);
	JTextField name = new JTextField(15);
	JTextField sales = new JTextField(15);
	DisplayPanel displayPanel = new DisplayPanel();


	newframe(){
		super("Monthly Sales");
		setSize(350,300);
		setLocation(500,280);
		
		JPanel bigPanel = new JPanel(new BorderLayout());
		bigPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Monthly Sale"));
		
		bigPanel.add(new InputPanel(), BorderLayout.NORTH);
		bigPanel.add(displayPanel);
		bigPanel.add(new ButtonPanel(), BorderLayout.SOUTH);

		submit.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				displayPanel.addFiedls();
			}
		});
		
	    add(bigPanel);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	
	}
	
	// the panels to input the data that will be in the NORTH region
	class InputPanel extends JPanel {
		
		InputPanel() {
			super(new GridLayout(4, 3));
			add(new JLabel("Employee Id:"));
			add(id);
			add(new JLabel("Employee Name:"));
			add(name);
			add(new JLabel("Employee Sales:"));
			add(sales);
			// center Sumbit button
			JPanel p = new JPanel(new GridLayout(1,2));
			p.add(new JLabel(""));
            p.add(submit);
			add(p);
		}
	}
	// the output fields which will be in the CENTER region
	class DisplayPanel extends JPanel {
		
		// the 3 headers
		String[] header = {"Employee ID", "Employee Name", "Employee Sales"};
		// the 3 X 5 labels to display
		JLabel[][] labels = new JLabel[5][3];
		// index which row I am at
		int row = 0;
		
		DisplayPanel() {
			// 6 rows and 3 columns
			super(new GridLayout(6, 3, 5, 5));
			// add the 3 header
			for(int i = 0; i < header.length; ++i)
				add(new JLabel(header[i]));
			// the other JLabel. Each row
			for(int i = 0; i < labels.length; ++i) {
				// each columns
				for(int j = 0; j < labels[i].length; ++j) {
					labels[i][j] = new JLabel("");
					labels[i][j].setOpaque(true);
					labels[i][j].setBackground(Color.WHITE);
					add(labels[i][j]);
				}
			}
		}
		// adds the new entry into the next one
		void addFiedls() {
			if(row == labels.length)
				return;              // sorry no more room
			labels[row][0].setText(id.getText());
			labels[row][1].setText(name.getText());
			labels[row][2].setText(sales.getText());
			++row;
		}
	}
	
	// the 3 buttons in the SOUTH region
	class ButtonPanel extends JPanel implements ActionListener {
        JButton min, max, exit;
        
		ButtonPanel() {
			min = new JButton("MIN");
			min.addActionListener(this);
			add(min);
			max = new JButton("MAX");
			max.addActionListener(this);
			add(max);
			exit = new JButton("EXIT");
			exit.addActionListener(this);
			add(exit);
		}
		
		public void actionPerformed(ActionEvent e) {
			Object o = e.getSource();
			if(o == min) {
				// the min button as been hit
			}
			else if(o == max) {
				// the max button has been hit
			}
			else {
				// the exit button has been hit
				System.exit(0);
			}
		}
	}
}


Was This Post Helpful? 1
  • +
  • -

#13 keziahcook  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 22-September 12

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 07:17 PM

Thank you very much sir!.
But when I debug it process complete and then run it no output T_T
I think something wrong in my PC.
Was This Post Helpful? 0
  • +
  • -

#14 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 07:21 PM

What do you mean "when I debug" ?

Quote

But when I debug it process complete and then run it no output T_T

what is no output T_T ?

It is a GUI application it shouldn't stop until you click on the Exit button or on the little icon on the top right corner
Was This Post Helpful? 0
  • +
  • -

#15 keziahcook  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 22-September 12

Re: How can i transfer the data to other txtfield when click submit

Posted 23 September 2012 - 07:34 PM

I think there's a problem in my java.
Attached Image

Is my java is an old version?

Compile file rather
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3