6 Replies - 791 Views - Last Post: 14 March 2009 - 09:29 AM Rate Topic: -----

#1 xCraftyx  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 258
  • Joined: 13-September 08

Setting properties in a GUI

Posted 13 March 2009 - 08:59 AM

I'm using Netbeans GUI Builder to create an interface for a tic tac toe game. I have a text field on the form and i want to change it from another class.
	// Variables declaration - do not modify
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JSeparator jSeparator1;
	private javax.swing.JSeparator jSeparator2;
	private javax.swing.JSeparator jSeparator3;
	private javax.swing.JSeparator jSeparator4;
	private javax.swing.JTextField p1MoveTxtField; //this is what i need to change
	private javax.swing.JTextField p2MoveTextField;
	private javax.swing.JButton pos11;
	private javax.swing.JButton pos12;
	private javax.swing.JButton pos13;
	private javax.swing.JButton pos21;
	private javax.swing.JButton pos22;
	private javax.swing.JButton pos23;
	private javax.swing.JButton pos31;
	private javax.swing.JButton pos32;
	private javax.swing.JButton pos33;
	// End of variables declaration


And the code leading up to where i change the property:
public void Play()
	{
		Scanner scanner = new Scanner(System.in);
		TTT_GUI gui = new TTT_GUI();
		int col = 5, row = 5;
		char[][] board = new char[row][col];

		/*###Initialize All Spots in Array###*/
		for (int i = 0; i <= col - 1; i++)
		{
			for (int j = 0; j <= row - 1; j++)
				board[j][i] = ' ';
		}

	   /*###Show Window###*/
	   gui.setVisible(true);

		int turns = 0;	 //keep track of turns in case of stalemate and to know when to start checking for a win
		int coord1 = 0, coord2 = 0; //coordinates
		boolean isValid = false; //for determining if input coords are taken or not
		boolean p1wins = false, p2wins = false; //for determining winner
		int testwin;		//used to determine the ASCII value of rows/columns
		boolean stalemate = false;

		/*###GAME LOOP###*/
		while (true)
		{
			//Loop until you get valid coordinates
			while(isValid == false)
			   /*###Take in coordinates for player1's move###*/
			  //right here is where i need to set he property



I thought it would be something like gui.p1MoveTxtField.text(""); but that doesn't work...what is the correct format for changing the properties of a text box (or other components?)

Is This A Good Question/Topic? 0
  • +

Replies To: Setting properties in a GUI

#2 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: Setting properties in a GUI

Posted 13 March 2009 - 07:33 PM

Which property ?
Was This Post Helpful? 0
  • +
  • -

#3 xCraftyx  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 258
  • Joined: 13-September 08

Re: Setting properties in a GUI

Posted 13 March 2009 - 09:34 PM

The text in p1MoveTxtField; The general format for changing properties of swing components would be helpful too

This post has been edited by xCraftyx: 13 March 2009 - 09:36 PM

Was This Post Helpful? 0
  • +
  • -

#4 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: Setting properties in a GUI

Posted 13 March 2009 - 09:46 PM

View PostxCraftyx, on 13 Mar, 2009 - 08:34 PM, said:

The text in p1MoveTxtField; The general format for changing properties of swing components would be helpful too

Which property ? Again :angry:
ForeGround color ? BackgGround color ? Font ? Size ? Location ? ActionListener ? Focus ?
Was This Post Helpful? 0
  • +
  • -

#5 xCraftyx  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 258
  • Joined: 13-September 08

Re: Setting properties in a GUI

Posted 13 March 2009 - 09:56 PM

Sorry I'm new to GUIs, I suppose the Font property since I'm trying to change the text
Was This Post Helpful? 0
  • +
  • -

#6 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: Setting properties in a GUI

Posted 14 March 2009 - 05:20 AM

View PostxCraftyx, on 13 Mar, 2009 - 08:56 PM, said:

Sorry I'm new to GUIs, I suppose the Font property since I'm trying to change the text

textfield.setText("Hello world");
the font is another issue
Was This Post Helpful? 1
  • +
  • -

#7 xCraftyx  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 258
  • Joined: 13-September 08

Re: Setting properties in a GUI

Posted 14 March 2009 - 09:29 AM

Thanks that's all i need for now
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1