Question

Exercise 1 1. Create a simple Graphical User Interface (GUI): Create new JFrameForm and use the Palette to drag and drop the
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/**
* The java program that prompts user to enter a month number
* If mont number is invalid then set text to invalid otherwise
* display the name of the month
* */

//JFrameForm.java
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
public class JFrameForm extends JFrame
{

   private JPanel contentPane;
   private JTextField textField;

   /**
   * Launch the application.
   */
   public static void main(String[] args) {
       EventQueue.invokeLater(new Runnable() {
           public void run() {
               try {
                   JFrameForm frame = new JFrameForm();
                   frame.setVisible(true);
               } catch (Exception e) {
                   e.printStackTrace();
               }
           }
       });
   }

   /**
   * Create the frame.
   */
   public JFrameForm() {
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setBounds(100, 100, 404, 168);
       contentPane = new JPanel();
       contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
       setContentPane(contentPane);
       contentPane.setLayout(null);
      
       JLabel lblConvertMonthNumber = new JLabel("Convert month number to month name :");
       lblConvertMonthNumber.setFont(new Font("Tahoma", Font.BOLD, 14));
       lblConvertMonthNumber.setForeground(Color.RED);
       lblConvertMonthNumber.setBounds(10, 11, 285, 34);
       contentPane.add(lblConvertMonthNumber);
      
       textField = new JTextField();
       textField.setBounds(10, 53, 285, 26);
       contentPane.add(textField);
       textField.setColumns(10);
      

       JLabel lblNewLabel = new JLabel("The month name is :");
      
      
       JButton btnNewButton = new JButton("GO!");
       btnNewButton.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent arg0) {
              //create an array of month names
               String monthNames[]= {"January","February","March","April","May","June","July",
           "August","September","October","November","December"};
               //Parset text to integer
               int userNumber=Integer.parseInt(textField.getText());
               //check if user numbre is invalid
               if(userNumber<1 || userNumber>12)
                   //set month as invalid
                   lblNewLabel.setText("Invalid");
               else
               {
                   //set mont name
                   lblNewLabel.setText("The month name is :"+monthNames[userNumber-1]);
               }

              
           }
       });
       btnNewButton.setBounds(310, 53, 68, 26);
       contentPane.add(btnNewButton);
       lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
       lblNewLabel.setBounds(10, 90, 285, 29);
       contentPane.add(lblNewLabel);
      
   }
}

Sample Output:

Convert month number to month name : GO! The month name is :

- O X Convert month number to month name : GO! Invalid

- 0 x Convert month number to month name : GO! The month name is : January

Add a comment
Know the answer?
Add Answer to:
Exercise 1 1. Create a simple Graphical User Interface (GUI): Create new JFrameForm and use the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • GUI programming

    Exercise 1: Create a simple Graphical User Interface (GUI): Create new JFrameForm and use the Palette to drag and drop the Swing Containers and Controllers like the figure shown. Your Form should accept a file name in its text field. When the user presses OK Button, the content of the String array appear in the Text area below. Handle all Exceptions (File Not Found Exception)

  • JAVA Create a simple Graphical User Interface (GUI) in java with the following requirements:  The...

    JAVA Create a simple Graphical User Interface (GUI) in java with the following requirements:  The interface components will appear centered in the interface, and in two rows. o Row one will have a Label that reads “Please enter a valid integer:” and a Text Field to take in the integer from the user. o Row two will have a Button that when pressed converts the integer to binary  The conversion will be completed using recursion – A separate...

  • Graphical User Interface Programming (Code using JavaScript w/ Intellij idea) This assignment can be done using...

    Graphical User Interface Programming (Code using JavaScript w/ Intellij idea) This assignment can be done using either the Java Swing Library or the Java FX Library Design a universal remote control for an entertainment system such as (cable / TV, etc). Create the interface as a Java Intellij project. Optionally, you may design the interface for a smartphone. This is Very Important If you are implementing your design using the Swing Library, the assignment cannot be created using the GUI...

  • Using Python’s tkinter Graphical User Interface (GUI) module create a Python program to input the number...

    Using Python’s tkinter Graphical User Interface (GUI) module create a Python program to input the number of each type of coin a user has in their possession and then compute and display the total dollar and cents value of these coins. Your solution must accommodate Dollar, Half-Dollar, Quarter, Dime, Nickel, and Penny coins. Your solution must be robust against invalid inputs (i.e., negative value entered into any coin entry widget).

  • REQUIREMENTS: Write a Graphical User Interface (GUI) program using JavaFX that prompts the user to enter...

    REQUIREMENTS: Write a Graphical User Interface (GUI) program using JavaFX that prompts the user to enter a credit card number. Display whether the number is valid and the type of credit cards (i.e., Visa, MasterCard, American Express, Discover, and etc). The requirements for this assignment are listed below: • Create a class (CreditNumberValidator) that contains these methods: // Return true if the card number is valid. Boolean isValid(String cardNumber); // Get result from Step 2. int sumOfDoubleEvenPlace(String cardNumber); // Return...

  • I. User Interface Create a JavaFX application with a graphical user interface (GUI) based on the...

    I. User Interface Create a JavaFX application with a graphical user interface (GUI) based on the attached “GUI Mock-Up”. Write code to display each of the following screens in the GUI: A. A main screen, showing the following controls: • buttons for “Add”, “Modify”, “Delete”, “Search” for parts and products, and “Exit” • lists for parts and products • text boxes for searching for parts and products • title labels for parts, products, and the application title B. An add...

  • object oriented programming solve 2 quetions 9 Lab 8 - Graphical User Interface (GUI) The assignments...

    object oriented programming solve 2 quetions 9 Lab 8 - Graphical User Interface (GUI) The assignments for this week are to understand the use of tkinter modules to create GUI in Python. 9.1 Assignment 1 1. Create the following window using the tkinter module in Python. The button Quit closes the window, and the button Show prints the first name and last name entered in the Entry boxes. First Name Last Name Quit Show 2. Create the following window using...

  • Create a GUI (Graphical User Interface) in Python to graph the approximation of the Golden Spiral...

    Create a GUI (Graphical User Interface) in Python to graph the approximation of the Golden Spiral (Fibonacci Spiral). For this purpose, you must calculate the coordinates and radio, and simulate a process of infinity using a loop. In short, the graph must start in the lower left side corner and continue to its center infinitely. 34 21 13 34 21 13

  • New to matlab (Using Graphical User interface --(GUI)) I can't connect the final grade to its...

    New to matlab (Using Graphical User interface --(GUI)) I can't connect the final grade to its respective Letter grade and display it !! ei. ( 82.35 ---- B-) Please Help Thank You % Executes on button press in button. function button Callback(hobject, eventdata, handles) % hObject handle to button (see GCBO) % eventdata reserved - to be defined in a future version of % handles structure with handles and user data (see GUIDAT 89 89 87 x1=str2double (get(handles. input1, ·string'));...

  • Write a MATLAB Graphical User Interface (GUI) to simulate and plot the projectile motion – the...

    Write a MATLAB Graphical User Interface (GUI) to simulate and plot the projectile motion – the motion of an object projected into the air at an angle. The object flies in the air until the projectile returns to the horizontal axis (x-axis), where y=0. This MATLAB program should allow the user to try to hit a 2-m diameter target on the x-axis (y=0) by varying conditions, including the lunch direction, the speed of the lunch, the projectile’s size, and the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT