Create a GUI and It should look like the one in the figure • Make a subclass of
ID: 3592021 • Letter: C
Question
Create a GUI and It should look like the one in the figure
• Make a subclass of JFrame called ZodiacUI
• The constructor should set certain properties, such as location, size, what happens on close
• Make a private method to build and add the components
• The window should be 400 x 150 pixels
• The text field for the zodiac sign should not be enabled
• The background is DarkGray and the two panels are RGB 250, 230, 230 and RGB 250, 200, 200
• Make a Driver class to create your ZodiacUI
What's Your Sign? Input Area Enter your birthdate in DD/MMIYYYY format: Your Zodiac SignExplanation / Answer
Hi ,
Please find the following question's answer.
ZodiacUI.java:
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class ZodiacUI extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
//constructor
public ZodiacUI() {
setSize(500, 150);
setLocationRelativeTo(null);
setVisible(true);// making the frame visible
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("What's Your Sign?");
buildZodiacPanel();
}
// 400 width and 500 height
//private method with components
private void buildZodiacPanel() {
//base panel
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.setSize(500, 150);
panel.setBackground(Color.black);
//panel for the components birthday textfield
JPanel birthdayPanel = new JPanel();
birthdayPanel.setLayout(new GridLayout(1, 1));
birthdayPanel.add(new JLabel("Enter your birthday in DD/MM/YYYY format:"));
birthdayPanel.add(new JTextField(10));
birthdayPanel.setBorder(BorderFactory.createTitledBorder("Input Area"));
birthdayPanel.setBackground(new Color(250, 230, 230));
//panel for the components zodiacsign textfield
JPanel zodiacPanel = new JPanel();
zodiacPanel.setSize(10, 10);
zodiacPanel.setLayout(new GridLayout(1, 1));
JTextField zodiacSign = new JTextField(10);
zodiacSign.setEditable(false);//so that no one can edit the zodiac sign
zodiacPanel.add(zodiacSign);
zodiacPanel.setBorder(BorderFactory.createTitledBorder("Your Zodiac Sign"));
zodiacPanel.setBackground(new Color(250, 230, 230));
panel.add(birthdayPanel);
panel.add(zodiacPanel);
getContentPane().add(panel);
}
}
Driver.java:
public class Driver {
public static void main(String[] args) {
ZodiacUI zodiacUI = new ZodiacUI();
zodiacUI.revalidate();
}
}
Hope this helped you.