Fill This Form To Receive Instant Help
Homework answers / question archive / Write a program that creates a GUI displaying an octagon filled in yellow at the centre of a pane of 300x300 that will resize proportionately with the GUI window with a ration of 40% of GUI window
Write a program that creates a GUI displaying an octagon filled in yellow at the centre of a pane of 300x300 that will resize proportionately with the GUI window with a ration of 40% of GUI window. The GUI displays a text message (Assignment_5). The text message moves vertically arriving from the middle-top of the screen and disappearing in the middle-bottom circularly. The moving text stops if mouse is pressed and continues its motion when the mouse is released. Text has font type Times New Roman, font size of 20 points and font color blue. The following figure displays a few screenshots of the GUI. Title of GUI display Last Name, First Name, Student ID.
Answer:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.TitledBorder;
public class JustinDillingerHW3 extends JFrame {
//Create text fields and labels
private JTextField jtfFirstName = new JTextField(15);
private JTextField jtfLastName = new JTextField(15);
private JTextField jtfId = new JTextField(2);
private JLabel WelcomeMessage;
public static void main(String[] args){
JustinDillingerHW3 frame = new JustinDillingerHW3();
frame.setTitle("Hello User!!");
frame.setSize(300,250);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public JustinDillingerHW3(){
setLayout(new FlowLayout(FlowLayout.LEFT, 10, 20));
//add labels and text fields to the frame
add(new JLabel("First Name"));
add(jtfFirstName);
add(new JLabel("Last Name"));
add(jtfLastName);
add(new JLabel("StudentId"));
add(jtfID);
//Create Welcome button
JButton Welcome = new JButton("Click Here");
add(Welcome);
Welcome.addActionListener(new SubmitListener());
WelcomeMessage = (new JLabel(" "));
add(WelcomeMessage);
}
class SubmitListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String FirstName = jtfFirstName.getText();
String SurName = jtfLastName.getText();
WelcomeMessage.setText("Welcome, " + FirstName + " " + SurName);
}
}
}