This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Frame problem "Java"?  RSS feed

 
Pepo moussa
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi , if anyone can help me on the use of JFrame and JtextArea
well i am trying to write a method that will create a frame displays two text areas (JTextArea) in a grid layout (1 row, 2 columns). The first text area will be used to display the contents of the original array, before sorting, and the second one will be used to display the array contents sorted.

that how far i wrote and i really dont know where to go from here


public static void displayResults(JTextArea area, Room[] rooms,int length)
{
textArea.setEditable(false);

for ( int i = 0; i < rooms.length; i++ )
{
textArea.append(rooms1[i]+"\n");
}

JFrame bigTextArea = new JFrame("Queens College Rooms");
bigTextArea.setDefaultCloseOperation(JFr...
bigTextArea.setSize(400,600);
bigTextArea.getContentPane().add(textAre... BorderLayout.CENTER);
bigTextArea.setVisible(true);

}
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

For starters, the code to create the JFrame and the text areas should be outside of this method. This method is called twice, once for each text area, correct?

So you need to create the JFrame first, complete with GridLayout and two text areas. Then you can populate the two.

Does that help?

I'll move this to the AWT/Swing forum where GUI questions are discussed.
[ March 20, 2008: Message edited by: Ulf Dittmer ]
 
Pepo moussa
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i kind get the idea ,but still i don`t get why i should have the JFrame outside ? also i don`t know how i can make grid layout (1 row, 2 columns), if you have any sample code to show it that would be great thank you
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's good practice to first construct the GUI, and then start doing something with it. You really shouldn't mix the two.

The top-level code might look like this:

and the method to display the list:

[ March 20, 2008: Message edited by: Ulf Dittmer ]
 
Pepo moussa
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh ok now i got it, thank you man .that was not hard but they was i was thinking about it was totally wrong anyway thanks again .
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!