I'm a new entry in the programming world, so my skills are really poor. Anyway, I have to write a program for a school project, so I figured out one that seemd easy. Basically, I have just a Frame, a Button, a Panel (that I will use later) and two textfields. I need that when I write something in the first textfield and I press the button, the text will be scanned and put in a variable (that have to be processed later). The fact is that I dont't think I'm doing something right (just like I said, I'm just a beginner), and I can't figure out how to get what I want. Here's the code:
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.*;
import java.io.*;
import java.util.Timer.*;
import java.util.TimerTask.*;
import java.util.Scanner.*;
import java.lang.*;
import javax.sound.sampled.*;
public class ExamProgram {
public TextField scrivi;
public TextField vuraid;
public Button b;
public String s;
static class int timer4action(){return 0;}
static class chiusura implements WindowListener {
public void windowClosing (WindowEvent ev) {System.exit(0);}
public void windowClosed (WindowEvent ev) {}
public void windowOpened (WindowEvent ev) {}
public void windowActivated (WindowEvent ev) {}
public void windowDeactivated (WindowEvent ev) {}
public void windowIconified (WindowEvent ev) {}
public void windowDeiconified (WindowEvent ev) {}
} //Window events
public ExamProgram(){ //Constructor
//Frame inizialization
Frame f = new Frame ("Artificial wife");
f.setLayout(null);
f.setBackground(Color.white);
Image icona = Toolkit.getDefaultToolkit().getImage("src\\img\\Kurisu_profile.png");
f.setIconImage(icona);
f.setSize(800,600);
f.setVisible(true);
f.setResizable(false);
f.addWindowListener(new chiusura());
//Menù initialization.
MenuBar mb = new MenuBar();
Menu m1 = new Menu("File");
Menu m2 = new Menu("Opzioni");
Menu m3 = new Menu("Aiuto");
MenuItem mi1 = new MenuItem("Nuovo");
MenuItem mi2 = new MenuItem("Carica");
MenuItem mi3 = new MenuItem("Chiudi");
MenuItem mi4 = new MenuItem("Cambia lingua");
MenuItem mi5 = new MenuItem("FAQ");
MenuItem mi6 = new MenuItem("Manuale Elettronico");
m1.add(mi1); m1.add(mi2); m1.add(mi3);
m2.add(mi4);
m3.add(mi5);m3.add(mi6);
mb.add(m1); mb.add(m2); mb.add(m3);
f.setMenuBar(mb);
//Panel initialization
Panel waifu = new Panel();
waifu.setBackground(Color.PINK);
waifu.setBounds(25, 50, 750, 450);
waifu.setVisible(true);
f.add(waifu);
//Textfield n°1 initialization
scrivi = new TextField();
scrivi.setVisible(true);
scrivi.setBackground(Color.pink);
scrivi.setBounds(200,530, 400, 30);
f.add(scrivi);
//Button initialization
b = new Button("Send");
b.setBackground(Color.PINK);
b.setBounds(650, 530, 50, 30);
f.add(b);
//Event and Textfield n°2 initialization
vuraid = new TextField();
vuraid.setVisible(true);
vuraid.setEditable(false);
vuraid.setBackground(Color.green);
vuraid.setBounds(200,570, 400, 30);
f.add(vuraid);
b.addActionListener(new send());
}
public static void main(String[] args){
new ExamProgram();
}
}
And the action I want to get from the event:
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
public class send implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String textDialogue = new String();
textDialogue = scrivi.getText();
vuraid.setText(textDialogue);
}
}
Hope that I expressed myself properly so that you could get what I'm trying to ask. I tried to remove every italian text for letting the code be more understandable. Thank you very much for your attention.