Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 21st, 2006, 9:19 PM   #1
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
1st Java Project...Still

[php]
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;

public class lettercount
{
public static void main(String args[])
{
Panel pan=new Panel();
pan.setLayout(new BorderLayout()); // STUPID LAYOUT

JFrame app=new JFrame();

JButton fileButton=new JButton("Scan File");

char[] letterArray=new char[26];
int[] letterCount=new int[26];
int count=0;

for(int i=97;i<=122;i++)
{
letterArray[count]=(char)i;
//System.out.printf("%d = %s\n",count,letterArray[count]);
count++;
}

app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.add(pan);
//app.add(fileButton);
app.setSize(450,250);
app.setVisible(true);

}
}
[/php]

Im am completely clueless on how to implement this BorderLayout thing so that i can manage where my buttons and other components are being placed.

[php]
Panel pan=new Panel();
pan.setLayout(new BorderLayout());
[/php]

these 2 lines of code are my main problem.. do i have to make my class extend JPanel??? Im lost....


I would like to add that im using the API page from sun as my reference.
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Old Feb 21st, 2006, 9:25 PM   #2
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
Ok i added this

[php]
import java.awt.BorderLayout;
[/php]

but im starting to think this class and this syntax is for applets not console applications??? a little insight???
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Old Feb 21st, 2006, 9:35 PM   #3
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 748
Rep Power: 3 Jimbo is on a distinguished road
Here's a thing I did for a project way back when (I'm surprised I still have the code :eek: ) Maybe it'll help you get the idea... (dont worry about all the different variables, just look at the add() calls.) There's 2 BorderLayouts in this BTW, one inside of the other. This wasn't an applet either
public TrafficSimControl(TrafficSimModel m)
{
	world = m;
	this.setLayout(new BorderLayout());
	JPanel map = new JPanel();
	map.setLayout(new BorderLayout());
	// create and add the view to the model
	view = new TrafficView(world, this);
	world.addView(view);
	view.addMouseListener(new MapListener());
	// make scroll buttons
	JButton scrollNorth, scrollEast, scrollWest, scrollSouth;
	scrollNorth = new JButton("/\\");
	scrollEast = new JButton(">");
	scrollSouth = new JButton("\\/");
	scrollWest = new JButton("<");
	scrollNorth.addActionListener(new ScrollListener(Direction.NORTH));
	scrollEast.addActionListener(new ScrollListener(Direction.EAST));
	scrollSouth.addActionListener(new ScrollListener(Direction.SOUTH));
	scrollWest.addActionListener(new ScrollListener(Direction.WEST));
	map.add(BorderLayout.CENTER, view);
	map.add(BorderLayout.NORTH, scrollNorth);
	map.add(BorderLayout.EAST, scrollEast);
	map.add(BorderLayout.SOUTH, scrollSouth);
	map.add(BorderLayout.WEST, scrollWest);
	add(BorderLayout.CENTER, map);
	// make controlling buttons
	JPanel options = new JPanel();
	JButton pause = new JButton("pause");
	JButton resume = new JButton("resume");
	options.add(pause);
	options.add(resume);
	options.setBackground(Color.black);
	add(BorderLayout.SOUTH, options);
	// set up listeners for buttons
	ButtonListener buttonListener = new ButtonListener();
	pause.addActionListener(buttonListener);
	resume.addActionListener(buttonListener);
}
Jimbo is offline   Reply With Quote
Old Feb 21st, 2006, 9:38 PM   #4
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
can you give me a list of the imports...??? and of the surrounding class so i can see if u used this..

extends JPanel
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Old Feb 21st, 2006, 9:43 PM   #5
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
GRRR ok i really appreciate your help.. i used a borderlayout to add the button to the panel.. BUT it still takes up the entire EAST site or whatever side i put it on.. WHY CAN'T I CONTROL THE SIZE OF THE STUPID BUTTON... omg i hate java.

[php]
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;

import java.awt.BorderLayout;

public class lettercount extends JPanel
{
public static void main(String args[])
{
JPanel pan=new JPanel();
pan.setLayout(new BorderLayout());
JFrame app=new JFrame();
JButton fileButton=new JButton("Scan File");

char[] letterArray=new char[26];
int[] letterCount=new int[26];
int count=0;

for(int i=97;i<=122;i++)
{
letterArray[count]=(char)i;
//System.out.printf("%d = %s\n",count,letterArray[count]);
count++;
}

pan.add(BorderLayout.EAST, fileButton);

app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.add(pan);
app.setSize(450,250);
app.setVisible(true);

}
}
[/php]
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Old Feb 21st, 2006, 9:50 PM   #6
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
i can't even control the sizeof the panel or where the panel is being placed... how do i put multiple panels on one frame??? or a row of buttons down the right side of a panel???? this is so damn crazy
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Old Feb 21st, 2006, 9:51 PM   #7
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 837
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Java layouts suck... you should use a program that lets you drag and drop buttons onto a window, move them around and resize them. I think it's a waste of time learning layouts in Java. If you can't find a program like the one I described, I suggest absolutely positioning everything in the window using x and y coordinates, which gives you complete control over how everything is positioned (you can use getWidth() and getHeight() to allow elements to move and resize themselves when the window is resized).
titaniumdecoy is offline   Reply With Quote
Old Feb 21st, 2006, 9:57 PM   #8
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
First off lol, this is for school i must do it this way. Second... OMG that is my whole problem.. i want to use X and Y coordinates to position them.. i have said that from the start in a previous thread. Can you give me examples on how to take control and position each one of my components seperatly using x and y coordinates.. thanks!
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Old Feb 21st, 2006, 10:08 PM   #9
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 837
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Try something like the following:

getContentPane().setLayout(null);

getContentPane().add(element);
element.setBounds(24,500,72,36); // x, y, width, height
element.setVisible(true);
titaniumdecoy is offline   Reply With Quote
Old Feb 21st, 2006, 11:04 PM   #10
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
what class does getContentPane() come from?
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:05 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC