Hello...

Like the title already says, i have a Panel with a TextField and when a text is entered, i want it to appear on a JLabel that is located on another Panel. Can someone give me the Syntax? Or is it more complicated to do?
I do not use a Database since i dont know yet how to imply it in Java.
Thank you for your help!!!

To give you my code for my first Panel that contains the TextField(txtName)

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

import java.awt.event.*;


public class NameScreen extends JDialog {
	
	JPanel frmName = new JPanel();
	JLabel lblJtitle = new JLabel("Java Questions");
	JLabel lblName = new JLabel("Please Enter Your Name:");
	JLabel lblImage7 = new JLabel(new ImageIcon("D:\\Schule\\Java Projects\\Final Java2\\geld_0010.gif"));
	JTextField txtName = new JTextField("");
	JButton cmdOk = new JButton("OK");
	JButton cmdCancel = new JButton("Cancel");
	
	
	
	public NameScreen() {
		
		setSize(450,300);
		setLocation(600,300);
		setTitle("Do you know...?");
		setVisible(true);
		setResizable(false);
		frmName.setLayout(null);
		
		
		frmName.setBackground(Color.BLACK);
		
		lblJtitle.setBounds(163,100,170,30);
		lblJtitle.setFont(new Font("Arial", Font.BOLD, 16));
		lblJtitle.setForeground(Color.WHITE);
		
		lblName.setBounds(50,140,180,40);
		lblName.setForeground(Color.YELLOW);
		lblName.setFont(new Font("Arial", Font.BOLD, 14));
		
		cmdOk.setBounds(120,200,80,30);
		cmdCancel.setBounds(250,200,80,30);
		
		txtName.setBounds(240,140,150,30);               //TextField is here
		txtName.setFont(new Font("Arial", Font.BOLD, 20));
		
		lblImage7.setBounds(180,20,100,80);
		
		frmName.add(lblName);
		frmName.add(txtName);
		frmName.add(lblImage7);
		frmName.add(cmdOk);
		frmName.add(cmdCancel);
		frmName.add(lblJtitle);
		
		
		getContentPane().add(frmName);
		
		
		
		cmdOk.addActionListener(new ActionListener() 
		{
	       
	    		public void actionPerformed(ActionEvent e)
	    		{
	    			dispose();
	    			new GameScreen().show();
	    				
	    		}	
	    		
	    });
		
		
		cmdCancel.addActionListener(new ActionListener() 
		{
	       
	    		public void actionPerformed(ActionEvent e)
	    		{
	    			dispose();
	    			new ChoosingScreen().show();
	    				
	    		}	
	    		
	    });
		
				
	}	

}

Here is my Code for the other Panel that contains the JLabel(lblPlayer) that i want to display the inputed text from TextField

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

import java.awt.event.*;


public class GameScreen extends JDialog {
	
	JPanel frmGame = new JPanel();
	JPanel frmQuestion = new JPanel();
	JPanel frmLevel = new JPanel();
	JLabel lblTitle = new JLabel ("Do you know...?"); 
	JLabel lblRemember = new JLabel("Remeber, no mistake is allowed!");
	JLabel lblPlayer = new JLabel("Player Name");                      //supposed it has the caption of the textField
	JLabel lblQuestion = new JLabel("For what das Java stands for?");
	JLabel lblPeso1 = new JLabel("    10 Pesos");
	JLabel lblPeso2 = new JLabel("    20 Pesos");
	JLabel lblPeso3 = new JLabel("    30 Pesos");
	JLabel lblPeso4 = new JLabel("    40 Pesos");
	JLabel lblPeso5 = new JLabel("    50 Pesos");
	JLabel lblPeso6 = new JLabel("    60 Pesos");
	JLabel lblPeso7 = new JLabel("    70 Pesos");
	JLabel lblPeso8 = new JLabel("    80 Pesos");
	JLabel lblPeso9 = new JLabel("    90 Pesos");
	JLabel lblPeso10 = new JLabel("   100 Pesos");
	JLabel lblImage6 = new JLabel(new ImageIcon("D:\\Schule\\Java Projects\\Final Java2\\fackel_0010.GIF"));
	JLabel lblImage7 = new JLabel(new ImageIcon("D:\\Schule\\Java Projects\\Final Java2\\fackel_0010.GIF"));
	JLabel lblReminder = new JLabel(new ImageIcon("D:\\Schule\\Java Projects\\Final Java2\\mann_0007.GIF"));
	JLabel lblPlayerIcon = new JLabel(new ImageIcon("D:\\Schule\\Java Projects\\Final Java2\\Nervous.GIF"));
	JButton cmdAnswer1 = new JButton("A");
	JButton cmdAnswer2 = new JButton("B");
	JButton cmdAnswer3 = new JButton("C");
	JButton cmdAnswer4 = new JButton("D");
	JButton cmdBackChoose = new JButton("Back to Main Menu");
	
	
	
	public GameScreen() {
		
		setSize(800,800);
		setLocation(400,50);
		setResizable(false);
		setTitle("DO YOU KNOW...?");
		setVisible(true);
		frmGame.setLayout(null);
		frmGame.setBackground(Color.BLACK);
		frmQuestion.setLayout(null);
		frmQuestion.setBackground(Color.BLUE);
		frmQuestion.setBounds(150,150,500,200);
		frmLevel.setLayout(null);
		frmLevel.setBackground(Color.WHITE);
		frmLevel.setBounds(660,400,130,300);
		
		
		lblTitle.setFont(new Font("Arial", Font.BOLD, 30));
		lblTitle.setForeground(Color.YELLOW);
		lblTitle.setBounds(280,30,260,50);
		lblQuestion.setBounds(150,150,500,200);
		lblQuestion.setForeground(Color.YELLOW);
		lblQuestion.setFont(new Font("Arial",Font.BOLD, 18));
		
		lblPeso1.setBounds(660,670,130,30);
		lblPeso1.setFont(new Font("Arial", Font.BOLD,22));
		lblPeso2.setBounds(660,640,130,30);
		lblPeso2.setFont(new Font("Arial", Font.BOLD,22));
		lblPeso3.setBounds(660,610,130,30);
		lblPeso3.setFont(new Font("Arial", Font.BOLD,22));
		lblPeso4.setBounds(660,580,130,30);
		lblPeso4.setFont(new Font("Arial", Font.BOLD,22));
		lblPeso5.setBounds(660,550,130,30);
		lblPeso5.setFont(new Font("Arial", Font.BOLD,22));
		lblPeso6.setBounds(660,520,130,30);
		lblPeso6.setFont(new Font("Arial", Font.BOLD,22));
		lblPeso7.setBounds(660,490,130,30);
		lblPeso7.setFont(new Font("Arial", Font.BOLD,22));
		lblPeso8.setBounds(660,460,130,30);
		lblPeso8.setFont(new Font("Arial", Font.BOLD,22));
		lblPeso9.setBounds(660,430,130,30);
		lblPeso9.setFont(new Font("Arial", Font.BOLD,22));
		lblPeso10.setBounds(660,400,130,30);
		lblPeso10.setFont(new Font("Arial", Font.BOLD,22));
		
		lblReminder.setBounds(10,580,80,200);
		lblRemember.setBounds(80,600,200,40);
		lblRemember.setForeground(Color.RED);
		
		lblPlayer.setBounds(360,740,100,40);
		lblPlayer.setFont(new Font("Arial", Font.BOLD,12));
		lblPlayer.setForeground(Color.YELLOW);
		lblPlayerIcon.setBounds(320,570,150,200);
		
		cmdAnswer1.setBounds(225,400,150,50);
		cmdAnswer2.setBounds(425,400,150,50);
		cmdAnswer3.setBounds(225,500,150,50);
		cmdAnswer4.setBounds(425,500,150,50);
		
		cmdBackChoose.setBounds(640,730,150,40);
		
		lblImage6.setBounds(100,245,50,110);
		lblImage7.setBounds(660,245,50,110);
		
		
	
		frmGame.add(lblPeso1);
		frmGame.add(lblPeso2);
		frmGame.add(lblPeso3);
		frmGame.add(lblPeso4);
		frmGame.add(lblPeso5);
		frmGame.add(lblPeso6);
		frmGame.add(lblPeso7);
		frmGame.add(lblPeso8);
		frmGame.add(lblPeso9);
		frmGame.add(lblPeso10);
		frmGame.add(lblPlayer);
		frmGame.add(lblPlayerIcon);
		frmGame.add(lblTitle);
		frmGame.add(lblQuestion);
		frmGame.add(frmQuestion);
		frmGame.add(frmLevel);
		frmGame.add(lblImage6);
		frmGame.add(lblImage7);
		frmGame.add(cmdAnswer1);
		frmGame.add(cmdAnswer2);
		frmGame.add(cmdAnswer3);
		frmGame.add(cmdAnswer4);
		frmGame.add(lblReminder);
		frmGame.add(lblRemember);
		frmGame.add(cmdBackChoose);
		
		
		
		getContentPane().add(frmGame);
		
		
		
		
		cmdBackChoose.addActionListener(new ActionListener() 
		{
	       
	    		public void actionPerformed(ActionEvent e)
	    		{
	    			dispose();
	    			new ChoosingScreen().show();
	    				
	    		}	
	    		
	    });
			
	}
}

What about passing the variable as a parameter for the other panels constructor?

What about passing the variable as a parameter for the other panels constructor?

Thank you i will try it... But this is true to pass it from 1 Panel to another one?
I dont need to indicate the class where the textField is located?

You can pass it through the constructor of the second panel's class constructor, like this:

public GameScreen(String name)
{
...
}

So when you call it from the first panel, you call it this way:

new GameScreen(txtName.Text).show();
commented: Straight to the point and without cryptic extra explainations. +2

You can pass it through the constructor of the second panel's class constructor, like this:

public GameScreen(String name)
{
...
}

So when you call it from the first panel, you call it this way:

new GameScreen(txtName.Text).show();

Thanks a lot i think i can figure it out now by my own...
Thank you for your quick help.

Always a pleasure ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.