![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
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 |
|
|
|
|
|
#2 |
|
Expert Programmer
|
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
}
}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();
}
} |
|
|
|
|
|
#3 |
|
Sexy Programmer
|
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! |
|
|
|
|
|
#4 |
|
Expert Programmer
|
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.
|
|
|
|
|
|
#5 |
|
Sexy Programmer
|
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! |
|
|
|
|
|
#6 |
|
Expert Programmer
|
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.
|
|
|
|
|
|
#7 | |
|
Programmer
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3
![]() |
Quote:
|
|
|
|
|
|
|
#8 |
|
Sexy Programmer
|
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! |
|
|
|
|
|
#9 |
|
Expert Programmer
|
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 |
|
|
|
|
|
#10 |
|
Expert Programmer
|
[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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|