Question

In: Computer Science

Please use Java language! with as much as comment! thanks! Write a program that displays a...

Please use Java language! with as much as comment! thanks!

Write a program that displays a frame with a three labels and three textfields. The labels should be "width:", "height:", and "title:" and should each be followed by one textfield. The texfields should be initialized with default values (Example 400, 600, default title), but should be edited by the user. There should be a button (label it whatever you want, I don't care). If you click the button, a new frame should become visible that has the title and dimensions the user entered in the textfields on the first frame (or the default values, if the user did not enter anything).

Use JPanels and the EXIT_ON_CLOSE statement. Give the first panel some proper dimensions using the setSize method.

Solutions

Expert Solution

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;

public class NewWindow {
   static JFrame frame = new JFrame("JFrame Example");

   public static void main(String s[]) {
       JPanel panel = new JPanel();
       panel.setLayout(null);
       JLabel label1 = new JLabel("Height");
       label1.setBounds(200, 50, 150, 30);

       final JTextField height = new JTextField(10);
       height.setBounds(300, 50, 100, 30);

       JLabel label2 = new JLabel("Width");
       label2.setBounds(200, 100, 150, 30);
       final JTextField width = new JTextField(10);
       width.setBounds(300, 100, 100, 30);

       JLabel label3 = new JLabel("Title");
       label3.setBounds(200, 150, 150, 30);
       final JTextField title = new JTextField(10);
       title.setBounds(300, 150, 100, 30);

       JButton login = new JButton();
       login.setText("Create Window");
       login.setBounds(300, 220, 250, 20);

       login.addActionListener(new ActionListener() {

           @Override
           public void actionPerformed(ActionEvent aE) {
               int h = Integer.parseInt(height.getText());
               int w = Integer.parseInt(width.getText());
               String t = title.getText();
               JFrame f = new JFrame(t);
               f.setSize(w, h);
               f.setVisible(true);
               f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

           }
       });

       panel.add(label1);
       panel.add(label2);
       panel.add(label3);
       panel.add(height);
       panel.add(width);
       panel.add(title);
       panel.add(login);
       frame.add(panel);

       frame.setSize(600, 300);
       frame.setLocationRelativeTo(null);
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setVisible(true);
   }
}

Note : If you like my answer please rate and help me it is very Imp for me


Related Solutions

Please use Java language! with as much as comment! thanks! Write a program that displays a...
Please use Java language! with as much as comment! thanks! Write a program that displays a frame with a three labels and three textfields. The labels should be "width:", "height:", and "title:" and should each be followed by one textfield. The texfields should be initialized with default values (Example 400, 600, default title), but should be edited by the user. There should be a button (label it whatever you want, I don't care). If you click the button, a new...
Please use java language in an easy way and comment as much as you can! Thanks...
Please use java language in an easy way and comment as much as you can! Thanks 1. A driver class with a main method, which creates instances of various objects (two of each subclass) and adds them as items to an ArrayList named "inventory". A foreach loop should loop through the ArrayList and call the use() method of each item. Define the ArrayList in a way that it only holds elements of the GameItem class and its subclasses. Make proper...
Please use java language in an easy way and comment as much as you can! Thanks...
Please use java language in an easy way and comment as much as you can! Thanks (Write a code question) Write a generic method called "findMin" that takes an array of Comparable objects as a parameter. (Use proper syntax, so that no type checking warnings are generated by the compiler.) The method should search the array and return the index of the smallest value. (Analysis of Algorithms question) Determine the growth function and time complexity (in Big-Oh notation) of the...
Please use java language in an easy way and comment as much as you can! Thanks...
Please use java language in an easy way and comment as much as you can! Thanks (Write a code question) Write a generic method called "findMin" that takes an array of String objects as a parameter. (Use proper syntax, so that no type checking warnings are generated by the compiler.) The method should search the array and return the index of the smallest value.
Please use Java language with comments! Thanks! Write a program that will display multiple dots move...
Please use Java language with comments! Thanks! Write a program that will display multiple dots move across the Frame and randomly change direction when they hit the edge of the screen. Do this by creating a Dot class and making each dot an object of that class. You may reuse code written in class for this part of the assignment. Create a subclass of the Dot class called PlayerDot that is controlled by the player through keyboard input (arrow keys)...
write code in java and comment. thanks. the program is about interface . Implement the basics...
write code in java and comment. thanks. the program is about interface . Implement the basics of Fitness and types of Fitness: Aerobic. Implement specific Fitness types such as Swimming, Cycling, Fitness Task: public interface Fitness (10pts) This will be used as a starting point for deriving any specific Fitness type. Every fitness exercise type has one or more muscle group it affects. Therefor a Fitness has the following abstarct method (Note that all methods in an interface are abstract...
Please use Java language in an easy way with comments! Thanks! Write a static method called...
Please use Java language in an easy way with comments! Thanks! Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the...
Please use Java language in an easy way with comments! Thanks! Write a static method called...
Please use Java language in an easy way with comments! Thanks! Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the...
Please write code in java and comment . thanks Item class A constructor, with a String...
Please write code in java and comment . thanks Item class A constructor, with a String parameter representing the name of the item. A name() method and a toString() method, both of which are identical and which return the name of the item. BadAmountException Class It must be a RuntimeException. A RuntimeException is a subclass of Exception which has the special property that we wouldn't need to declare it if we need to use it. It must have a default...
Please use Phyton to write a program: Write a program that calculates and displays the total...
Please use Phyton to write a program: Write a program that calculates and displays the total bill at a restaurant for a couple that is dining. The program should collect from the couple, cost of each meal, and the percentage of the final cost that they would like to tip. The sales tax in the state where the restaurant exists is 7.5%. Display to the user, line by line: Total Cost of Both Meals Sales Tax in dollars Tip in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT