Question

In: Computer Science

Your mission is to create your own application with the following minimum requirements: A JFrame and...

Your mission is to create your own application with the following minimum requirements:
A JFrame and a (non-modal) JDialog.
A JTabbedPane and JScrollPane.
Nested JPanels including the following layout managers: GridLayout, FlowLayout, BorderLayout
Some interaction widgets (JButton, etc.) on every JPanel and tab.
Reasonable behavior when the JFrame is resized.
NOTE: You may not use GridBagLayout, Free Design, Box, Overlay, Null or Absolute Layout anywhere in the project.

Solutions

Expert Solution

package gui;

import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 * @see http://stackoverflow.com/a/5696404/230513
 */
public class Launcher extends JPanel implements Runnable {

    private final JLabel label = new JLabel();
    private final JButton launch = new JButton();
    ProcessBuilder pb = new ProcessBuilder(
        "java", "-cp", "build/classes", "gui.Launcher$DialogTest");
    private volatile Process proc;

    public static void main(String[] args) {
        EventQueue.invokeLater(new Launcher()::createGUI);
    }

    private void createGUI() {
        final JFrame frame = new JFrame();
        frame.setLayout(new GridLayout(0, 1));
        frame.add(new Launcher());
        frame.add(new Launcher());
        frame.add(new Launcher());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }

    public Launcher() {
        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        this.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
        launch.setAlignmentX(0.5f);
        label.setAlignmentX(0.5f);
        launch.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (proc == null) {
                    launch.setText("Terminate");
                    label.setText("Status: run");
                    new Thread(Launcher.this).start();
                } else {
                    proc.destroy();
                    reset();
                }
            }
        });
        this.add(launch);
        this.add(label);
        reset();
    }

    @Override
    public void run() {
        try {
            proc = pb.start();
            proc.waitFor();
        } catch (IOException | InterruptedException ex) {
            ex.printStackTrace(System.err);
        }
        EventQueue.invokeLater(this::reset);
    }

    private void reset() {
        proc = null;
        launch.setText("Launch");
        label.setText("Status: idle");
    }

    private static class DialogTest {

        public static void main(String[] args) {
            EventQueue.invokeLater(() -> {
                JOptionPane.showMessageDialog(null, "Running",
                    "Test", JOptionPane.INFORMATION_MESSAGE);
                System.exit(0);
            });
        }
    }
}

Related Solutions

I need a Java application with a GUI that includes the following requirements: Three classes minimum...
I need a Java application with a GUI that includes the following requirements: Three classes minimum At least one class must use inheritance At least one class must be abstract Utilization of “get set” method. (get; set; =  is related to how variables are passed between different classes. The get method is used to obtain or retrieve a particular variable value from a class. A set value is used to store the variables. The whole point of the get and set...
Create your own programming application and give a brief description of the system.
Create your own programming application and give a brief description of the system.
You will design and create your own GUI application for the Bank project. This project should...
You will design and create your own GUI application for the Bank project. This project should be designed and written by Java programming. The requirements of the program: 1. The program will be best implemented as a multi-file program for each class. 2. The parameters and return types of each function and class member should be decided in advance. You may need to add more member variables and functions to the classes than those listed below. Also, you can throws...
Write a Java application that implements the following class(es) as per business requirements mentioned below: Create...
Write a Java application that implements the following class(es) as per business requirements mentioned below: Create an abstract Insurance class (Insurance.java) that has the following instance variables: - Insurance number, - customer name, - start date of policy ( This should be represented by an object of predefined date class in java), - customer address [( Create a new Address class ( Address.java ) having following instance data members: House number , Street name, City, Province, Zip code. Implement getter...
be the chief Software Engineer, and your mission is to describe functional and non-functional requirements, as...
be the chief Software Engineer, and your mission is to describe functional and non-functional requirements, as good and detailed as possible. When you are missing data, you have to make assumptions (sometimes wild ones). No one can really answer your questions, and you have a presentation to the higher management in 45 min sharp. By then, you have to construct a document, with a very small ( no more than 10 lines) executive description, and no more than two A4...
Your task is to build an Android application that satisfies the following requirements: Has two activities:...
Your task is to build an Android application that satisfies the following requirements: Has two activities: MainActivity that implements the main functionality of the application and AboutActivity that shows your full name as per college record and student id The AboutActivity should be available through a menu A back button should appear in the ActionBar of the AboutActivity that takes user back to the MainActivity. It should be done through configuration! MainActivity should implement the following functionality o read the...
Respond to the following in a minimum of 300 words & in your OWN words. What...
Respond to the following in a minimum of 300 words & in your OWN words. What recommendations would you give to someone wanting to improve his or her cardiovascular health? Give reasoning for each recommendation. What recommendations would you give to someone wanting to improve his or her gastrointestinal health? Give reasoning for each recommendation.
Respond to the following in a minimum of 200 words. Answers must be in your own...
Respond to the following in a minimum of 200 words. Answers must be in your own words. Please do not copy and paste from the internet! Which immunity type would you say is the most beneficial? Please explain your answer. How can you improve this immunity type's ability to fight infection?
Create a simple C++ application that will exhibit concurrencyconcepts. Your application should create two threads...
Create a simple C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0. For your created code, provide a detailed analysis of appropriate concepts that could impact your application. Specifically, address:Performance issues with concurrencyVulnerabilities exhibited with use of stringsSecurity of the data types exhibited.
Create your own e-commerce business in Saudi Arabia (website or mobile application), you need to explain...
Create your own e-commerce business in Saudi Arabia (website or mobile application), you need to explain the process that you will follow in building your e-commerce presence. Before you begin to build a website or app of your own, there are some important questions you will need to think about and answer. The answers to these questions will drive the development and implementation of your e-commerce presence. Set up Your E-Commerce Presence What is the idea? (the visioning process) Introduce...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT