i need a java program please help Create the following graphical user interface
ID: 653591 • Letter: I
Question
i need a java program please help
Create the following graphical user interface (GUI) program. There will be NO functionality in the GUI. It is ONLY the display. Nothing will happen when you click the buttons. Frame ? Meters / Feet Converter Set frame size to 325px wide by 225px in height Set window to open at location 100, loo on the screen Panel 1 ? Convert Meters to Feet Components: label, text field, button Set panel background to light yellow (255, 255, 224) Set the label font color to navy (0, 0, 128) Set the button background color to navy (0, 0, 128) Set the button font color to white (255, 255, 255) Set keyboard shortcut for button to F PaneI 2 ? Convert Feet to Meters Components: label, text field, button Set panel background to linen (250, 240, 230) Set the label font color to maroon (128, 0, 0) Set keyboard shortcut for button to M Set the button background color to maroon (128, 0, 0) Set the button font color to white (255, 255, 255)Explanation / Answer
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class GUI {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame = new JFrame("Meters / Feet Converter"); //declare a frame with title
frame.setSize(325, 225); //set the size of frame
frame.setLocation(100, 100); //set the location of frame on screen
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //set default close operation for frame
JPanel panel1 = new JPanel(); //declare a panel object
Color lightYellowColor=new Color(255,255,224); //declare a color object
panel1.setBackground(lightYellowColor); //set background color of panel
JLabel label1 = new JLabel("Convert Meters to Feet"); //declare label object
Color navyColor=new Color(0,0,128); //declare color object
label1.setForeground(navyColor); //set font color of label
JTextField text1=new JTextField(); //declare a text field object
text1.setSize(100,100); //set the size of the text field
text1.setText(" ");
JButton button1 = new JButton(); //create a button object
button1.setBackground(navyColor); //set background color of the button
Color whiteColor=new Color(255,255,255); //declare a color object
button1.setForeground(whiteColor); //set foreground color of button
button1.setText("Convert"); //set text for button
button1.setMnemonic(KeyEvent.VK_F); //set shortcut key for button
panel1.add(label1); //add label to panel
panel1.add(button1); //add button to panel
panel1.add(text1,BorderLayout.CENTER); //add text to panel
frame.add(panel1,BorderLayout.PAGE_START); //add panel to start of frame
JPanel panel2 = new JPanel(); //declare a panel object
Color linenColor=new Color(250,240,230); //declare a color object
panel2.setBackground(linenColor); //set background color for panel
JLabel label2 = new JLabel("Convert Feet to Meters"); //declare a lebel object
Color maroonColor=new Color(128,0,0); //declare a color object
label2.setForeground(maroonColor); //set font color of label
JButton button2 = new JButton(); //declare a button object
button2.setBackground(maroonColor); //set background color for button
button2.setForeground(whiteColor); //set font color for button
button2.setText("Convert"); //set text for button
button2.setMnemonic(KeyEvent.VK_M); //set shortcut key for button
panel2.add(label2); //add label to panel
panel2.add(button2); //add button to panel
frame.add(panel2,BorderLayout.CENTER); //add panel to center of frame
frame.pack(); //size the frame so that all its contents are at or above their preferred sizes
frame.setVisible(true); //set frame to visible
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.