In my Java course I have to create a GUI class that interacts with the user and a Logic class that handles the interaction. Since I find this very complicated and hard to understand, I'm looking for some help that can inspire me to continue.
Until now I have just used a text based Menu class with a Swich statement to handle simple input with Scanner and then handle all get and set methods. But I guess I don't need that anymore, and instead could create some Logic class to handle all get and set methods in objects depending on the input from the user. But to begin, how do I create a simple menu in a window and get input value from a GUI class to this Logic class and it's methods?
I add a simple GUI test class that I have done to start this task, but I'm afraid something is missing?
import javax.swing.*;
import java.awt.*;
class Guitest extends JFrame {
JTextField inputLine;
JLabel text;
Container contentPane;
// constructor
public Guitest() {
contentPane = getContentPane();
contentPane.setBackground(Color.WHITE);
setTitle("Test GUI");
setSize(400,200);
setLocation(400,400);
contentPane.setLayout(new FlowLayout(FlowLayout.LEFT));
text = new JLabel("Enter name of new customer");
contentPane.add(text);
inputLine = new JTextField();
inputLine.setColumns(10);
contentPane.add(inputLine);
setDefaultCloseOperation( EXIT_ON_CLOSE );
}
}
And I also add a simple class that make an instance of the window and make it visible. Perhaps this class could be the Logic class?
class Showgui {
// main
public static void main(String[] args) {
Guitest mywindow;
mywindow = new Guitest();
mywindow.setVisible(true);
}
}
All help is preciated! Thanks!