The GUIFlowLayout is giving me some trouble, the GUIFrame works fine.
I have copied this from the Java programming book which I am using (Introduction to JAVA, eight edition, by Y. Daniel Liang).
I get red error lines under 'setLayout', all of the 'add' words, and all the 'setTitle, setSize' and so on.
I don't know how to solve this, as all of the previous examples in the book have been flawless so far.
All of the errors say: "The method (method) is undefined for the type GUIFlowLayout.
import javax.swing.*;
import java.awt.FlowLayout;
public class GUIFlowLayout extends GUIFrame {
public GUIFlowLayout() {
setLayout(new FlowLayout(FlowLayout.LEFT, 10, 20));
add(new JLabel("First Name"));
add(new JTextField(8));
add(new JLabel("MI"));
add(new JTextField(1));
add(new JLabel("Last Name"));
add(new JTextField(8));
}
public static void main(String[] args) {
GUIFlowLayout frame = new GUIFlowLayout();
frame.setTitle("ShowFlowLayout");
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
The extended class GUIFrame:
import javax.swing. *;
public class GUIFrame {
public static void main(String[] args) {
JFrame frame = new JFrame("Frame");
frame.setSize(400, 300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}