1. Write a Java application to display the following GUI. At this point you are
ID: 3661158 • Letter: 1
Question
1. Write a Java application to display the following GUI. At this point you are only implementing the display. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /?>
This program has the following requirements:
1. The textfield should accommodate 3 characters.
2. The X and Y labels should be next to the corresponding textfields.
Hint: Put each label and its adjacent text field into a panel, then put both panels into another panel!
3. The buttons should have 10 pixels horizontal spacing and 5 pixels vertical spacing.
4. For the layout of the JFrame, use FlowLayout( FlowLayout.CENTER, 10, 5).
5. Your application should be implemented in a single class. The main method of the class does nothing more than create an object of the class. The constructor of the class creates and displays the GUI. The constructor may call other methods of the class if needed.
6. Do not use inheritance for this program. Use a JFrame member variable as the main window object for this program.
Explanation / Answer
import javax.awt; import java.awt.*; class GUI { JTextField tf1; JLabel X,Y; JButton b; FlowLayout ff; JFrame f; GUI() { tf=new JTextField(3); X=new JLabel("X"); Y=new JLabel("Y"); b=new JButoon("b",10,5); f=new JFrame(); ff=new FlowLayout(FlowLayout.CENTER,10,5); f.add(ff); X.add(f); tf1.add(f); Y.add(f); tf1.add(f); b.add(f); } public static void main(String ard[]) { new GUI(); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.