Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Feb 24th, 2006, 5:20 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
Java Questions

@titaniumdecoy: thanks a ton for your help with component layouts.

New Questions:

Im having fun with my new good looking button... with one problem i need to take control of it? Example-> JButton1_Click or Button_Down. How do i take control of component events???

Aside from Scanner class is there an entire class deticated to file i/o? If not what is the highly recommended class for performing this operation.
__________________
"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 24th, 2006, 5:54 PM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Create a class that extends JButton and implements ActionListener:

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

class MyButton extends JButton implements ActionListener {
	// Constructor
	MyButton() {
		super("Press me!");
		addActionListener(this);
	}
	// Implement the actionPerformed method
	// This is an abstract method in ActionListener
	public void actionPerformed(ActionEvent arg0) {
		// Do something when pressed
	}
}
It is common practice for such a class to be an inner class (so, for example, you would copy and paste the code above into the class that will be using it, and create an instance of MyButton instead of JButton).

If you need to know more than just when the button is pressed, you can implement MouseListener.

Here is a simple example of I/O that reads the first line of file.in and writes it to file.out.

import java.io.*;
class IOTest {
  public static void main (String [] args) throws IOException {
	RandomAccessFile f = new RandomAccessFile ("file.in", "r");
	PrintWriter out = new PrintWriter(
			new BufferedWriter(
			new FileWriter("file.out")));
	String firstLine = f.readLine();
	out.print(firstLine);
	out.close();
  }
}
titaniumdecoy is offline   Reply With Quote
Old Feb 24th, 2006, 7:04 PM   #3
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
my man titaniumdecoy knows his Java, how long you've been programming in Java man?
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Feb 24th, 2006, 7:42 PM   #4
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
About five years, since I was 13. I'm taking Computer Science AP this year at school (senior year!) which is taught in Java, so that helps.
titaniumdecoy is offline   Reply With Quote
Old Feb 24th, 2006, 7:45 PM   #5
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
next year, I'm a junior now, I am taking that class, the teacher was suprised when I passed the Intro to Java final exam with a 92%. Everyone in my school hates Java, thats b/c they do bullshit programs like working with other program, like this one called "Programming with Alice". 5 years huh? How long it take you to learn the Java itself and create kool looky GUI, which I am trying to learn now ,?
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Feb 24th, 2006, 8:06 PM   #6
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
I always hated Java GUIs, I've never made any worthwhile interface in Java. The layout managers suck ***, and I don't have the patience to position each item with coordinates. I learned Java from Beginning Java by Ivor Horton. It's a fat book.
titaniumdecoy is offline   Reply With Quote
Old Feb 24th, 2006, 8:12 PM   #7
jaeusm
Programmer
 
jaeusm's Avatar
 
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3 jaeusm is on a distinguished road
Quote:
I always hated Java GUIs, I've never made any worthwhile interface in Java. The layout managers suck ***, and I don't have the patience to position each item with coordinates.
I've never had an affinity for GUI programming in any language, but there are some tools available to ease Java GUI development.
jaeusm is offline   Reply With Quote
Old Feb 24th, 2006, 8:27 PM   #8
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
I personally like the GUI develop C#/ VB have, it mades things a lot easier!
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Feb 24th, 2006, 8:41 PM   #9
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
woot thanks a ton bro! the button works great... but ofcourse one problem leads to another... next step! before i use file i/o i need to be able to take control of the text in the JTextField so that i could pass it a function.

Oh another thing! when it comes time to use the fileName String (the variable passed to my function) do i replace file.in with the string name?
__________________
"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 24th, 2006, 8:43 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
[php]
RandomAccessFile f = new RandomAccessFile ("C:\fileName.txt", "r");
PrintWriter out = new PrintWriter(
new BufferedWriter(
new FileWriter("C:\fileOut.txt")));
String firstLine = f.readLine();
out.print(firstLine);
out.close();
[/php]

Like this?
__________________
"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 12:06 PM.

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