to make the program import the gui i used this statement
JFrame a = new GUI(); a.show();
but i have no idea how to make the gui file import a variable from the thread
plzz help thanks in advance




Posted 04 October 2011 - 03:15 PM
JFrame a = new GUI(); a.show();
Posted 04 October 2011 - 03:20 PM
GUI a = new GUI( variable );
Posted 04 October 2011 - 03:23 PM
GregBrannon, on 04 October 2011 - 03:20 PM, said:
GUI a = new GUI( variable );
Posted 04 October 2011 - 03:26 PM
This post has been edited by GregBrannon: 04 October 2011 - 03:27 PM
Posted 04 October 2011 - 03:31 PM
GregBrannon, on 04 October 2011 - 03:26 PM, said:
package lerox;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.JFrame;
public class Lerox extends JFrame {
public static void main(String[] args) throws IOException {
boolean exit = false;
JFrame a = new GUI();
a.show();
while (!exit){
loop();
}
}
public static void loop() throws IOException {
System.out.println("type a command or type \"help\" for command list");
boolean exit = false;
String n = System.getProperty("Line.seperator");
Scanner w2 = new Scanner(System.in);
String input = w2.nextLine();
if (input.equals("add movie")){
while (exit == false){
//writing movies to the list
System.out.println(" ");
System.out.println("what movie do you want to add to the list of watched movies ?");
Scanner w1 = new Scanner(System.in);
String m1 = w1.nextLine();
BufferedWriter write = new BufferedWriter(new FileWriter("C:/Users/vegard/workspace/lerox/src/movie lib.txt", (true)));
write.write(m1);
write.newLine();
write.flush();
write.close();
if (m1.equals ("exit")){
exit = true;
}
else {
System.out.print("movie " + m1);
System.out.println(" added to watchlist.");
System.out.println(" ");
}
}
}
if (input.equals("search")){
BufferedReader read = new BufferedReader(new FileReader("C:/Users/vegard/workspace/lerox/src/movie lib.txt"));
System.out.println("movie to search for ?");
Scanner s = new Scanner(System.in);
String s1 = s.nextLine();
String sr = read.readLine();
if (s1.equals(sr)){
System.out.println("u have already watched " + s1);
}
else{
System.out.println("you have not watched this movie!");
}
}
if (input.equals("help")){
System.out.println(" ");
System.out.println("1. search");
System.out.println("2. add movie");
System.out.println("3. help");
System.out.println(" ");
}
}
}
package lerox;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class GUI extends JFrame {
private JTextField textfield;
private JButton button;
private JLabel label;
public static void main(String[] args) {
}
public GUI() {
setSize(500, 250);
setResizable(false);
setTitle("movie library application.");
setLocation(500, 220);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
textfield = new JTextField("this is default text in the textfield");
add(textfield);
label = new JLabel("this is a JLabel!");
add(label);
button = new JButton("SEND");
add(button);
event e = new event();
button.addActionListener(e);
}
public class event implements ActionListener {
public void actionPerformed(ActionEvent e) {
label.setText(w2);
}
}
}
Posted 04 October 2011 - 03:48 PM
Posted 04 October 2011 - 03:49 PM
This post has been edited by GregBrannon: 04 October 2011 - 03:50 PM
Posted 04 October 2011 - 03:54 PM
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
