Question

This is all I have regarding the question import java.awt.*; import java.awt.event.*; import javax.swing.*; public class...

This is all I have regarding the question

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Quiz8_GUI

{

private JFrame frame;   

/**

* Create an Quiz8_GUI show it on screen.

*/

public Quiz8_GUI()

{

makeFrame();

}

// ---- swing stuff to build the frame and all its components ----

/**

* Create the Swing frame and its content.

*/

private void makeFrame()

{

frame = new JFrame("Quiz8_GUI");

makeMenuBar(frame);

Container contentPane = frame.getContentPane();

//set the Container to flow layout

//Your code goes here:

// create a button bOpen with "Open" shown on it, and add to the Panel

//add event processing to bOpen button, and and call openFile()

//when event is triggered

//Your code goes here:

//create a button bExit with "Exit" shown on it, and add to the Panel

//add event processing to bExit button, and  

//exit the system in exit button event.

//Your code goes here:

frame.pack();

frame.setVisible(true);

}

private void makeMenuBar(JFrame frame){   

JMenuBar menubar = new JMenuBar();

frame.setJMenuBar(menubar);

JMenu menu;

menu = new JMenu("File");

menubar.add(menu);  

//create the Open menu item called oItem and add it to File menu,

//add event listener and event processing to oItem, and call openFile()

//when event is triggered

//Your code goes here:

//create the Open menu item called eItem and add it to File menu,

//add event listener and event processing to eItem, and quit the program

//when event is triggered

//Your code goes here:

}

private void openFile(){

//For demonstration purpose, simply print out a word,

//instead of opening a real file

System.out.println("Open");

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Quiz8_GUI

{

private JFrame frame;

/**

* Create an Quiz8_GUI show it on screen.

*/

public Quiz8_GUI()

{

makeFrame();

}

// ---- swing stuff to build the frame and all its components ----

/**

* Create the Swing frame and its content.

*/

private void makeFrame()

{

frame = new JFrame("Quiz8_GUI");

makeMenuBar(frame);

Container contentPane = frame.getContentPane();

//set the Container to flow layout

//Your code goes here:
contentPane.setLayout(new FlowLayout());

// create a button bOpen with "Open" shown on it, and add to the Panel

//add event processing to bOpen button, and and call openFile()

//when event is triggered

//Your code goes here:
JButton bOpen=new JButton("Open");
contentPane.add(bOpen); //add button to panel;
//when button is clicked ActionEvent is generated and ActionListener interface is used to process tehe event
//event is handled using Anonymous class
bOpen.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
        //call openFile() when button is clicked
        openFile();
    }
});

//create a button bExit with "Exit" shown on it, and add to the Panel

//add event processing to bExit button, and

//exit the system in exit button event.

//Your code goes here:
JButton bExit=new JButton("Exit");
contentPane.add(bExit); //add button to panel;
//event is handled using Anonymous class
bExit.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
        System.exit(0);
    }
});

frame.pack();

frame.setVisible(true);

}

private void makeMenuBar(JFrame frame){

JMenuBar menubar = new JMenuBar();

frame.setJMenuBar(menubar);

JMenu menu;

menu = new JMenu("File");

menubar.add(menu);

//create the Open menu item called oItem and add it to File menu,

//add event listener and event processing to oItem, and call openFile()

//when event is triggered

//Your code goes here:
JMenuItem oItem=new JMenuItem("Open");
//add to file menu
menu.add(oItem);
oItem.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
        //call openFile() when button is clicked
        openFile();
    }
});

//create the Open menu item called eItem and add it to File menu,

//add event listener and event processing to eItem, and quit the program

//when event is triggered

//Your code goes here:
JMenuItem eItem=new JMenuItem("Exit");
//add to file menu
menu.add(eItem);
eItem.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
        System.exit(0);
    }
});

}

private void openFile(){

//For demonstration purpose, simply print out a word,

//instead of opening a real file

System.out.println("Open");

}
public static void main(String[] args)
{
new Quiz8_GUI();
}
}

Output

- x * Quiz8_GUI File Open Exit

when Open button is clicked the message displays as shown below

Quiz8_GUI File Open Exit A C:\WINDOWS\system32\cmd.exe - java Quiz8_GUI - O X C:\Users\hp>java Quiz8_GUI Open

when Open menu item is clicked under File menu the message displays as shown below

- * Quiz&_GUI File Open Exit Open Exit

Quiz8_GUI File Open Exit C. C:\WINDOWS\system32\cmd.exe - java Quiz8_GUI - O X C:\Users\hp>java Quiz8_GUI Open Open

if Exit button is clicked the window will be closed.

Add a comment
Know the answer?
Add Answer to:
This is all I have regarding the question import java.awt.*; import java.awt.event.*; import javax.swing.*; public class...
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
  • What is wrong with the following code? 2.67 pts class ExitListener implements ActionListener public void actionPerformed(ActionEvent...

    What is wrong with the following code? 2.67 pts class ExitListener implements ActionListener public void actionPerformed(ActionEvent event) { System.exit(0); 1 ActionListener exitListener - new ExitListener(); JMenu exitMenu - new JMenu( "Exit"); exitMenu.addActionListener(exitListener); JMenuBar menuBar = new JMenuBar(); menuBar.add(exitMenu); The ExitListener class is not public You cannot attach a listener to a menu, only to a menu item You cannot add a menu to the menu bar, only a menu item You need to use a menu listener, not an action...

  • import javax.swing.*; import java.awt.event.*; import java.awt.*; public class BookReview extends JFrame implements ActionListener {       private JLabel...

    import javax.swing.*; import java.awt.event.*; import java.awt.*; public class BookReview extends JFrame implements ActionListener {       private JLabel titleLabel;       private JTextField titleTxtFd;       private JComboBox typeCmb;       private ButtonGroup ratingGP;       private JButton processBnt;       private JButton endBnt;       private JButton clearBnt;       private JTextArea entriesTxtAr;       private JRadioButton excellentRdBnt;       private JRadioButton veryGoodRdBnt;       private JRadioButton fairRdBnt;       private JRadioButton poorRdBnt;       private String ratingString;       private final String EXCELLENT = "Excellent";       private final String VERYGOOD = "Very Good";       private final String FAIR = "Fair";       private final String POOR = "Poor";       String...

  • ***This is a JAVA question*** ------------------------------------------------------------------------------------------------ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*;...

    ***This is a JAVA question*** ------------------------------------------------------------------------------------------------ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class DrawingPanel implements ActionListener { public static final int DELAY = 50; // delay between repaints in millis private static final String DUMP_IMAGE_PROPERTY_NAME = "drawingpanel.save"; private static String TARGET_IMAGE_FILE_NAME = null; private static final boolean PRETTY = true; // true to anti-alias private static boolean DUMP_IMAGE = true; // true to write DrawingPanel to file private int width, height; // dimensions...

  • import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {...

    import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {    public static void createAndShowGUI() {        JFrame frame = new JFrame("Q1");        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        Font courierFont = new Font("Courier", Font.BOLD, 40);        Font arialFont = new Font("Arial", Font.BOLD, 40);        Font sansFont = new Font("Sans-serif", Font.BOLD, 20);        JLabel label = new JLabel("Enter a word"); label.setFont(sansFont);        Font font1 = new Font("Sans-serif", Font.BOLD, 40);       ...

  • JAVA Hello I am trying to add a menu to my Java code if someone can...

    JAVA Hello I am trying to add a menu to my Java code if someone can help me I would really appreacite it thank you. I found a java menu code but I dont know how to incorporate it to my code this is the java menu code that i found. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example");...

  • There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame...

    There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame { private int xPos, yPos; public Q4() { JPanel drawPanel = new JPanel() { @Override public void paintComponent(Graphics g) { super.paintComponent(g); // paint parent's background //complete this: } }; drawPanel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { //complete this :- set the xPos, yPos }    }); setContentPane(drawPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Mouse-Click Demo"); setSize(400, 250); setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() {...

  • Can you please fix the error. package com.IST240Apps; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*;...

    Can you please fix the error. package com.IST240Apps; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; import java.net.*; public class LinkRotator extends JFrame implements Runnable, ActionListener { String[] pageTitle = new String[5]; URI[] pageLink = new URI[5]; int current = 0; Thread runner; JLabel siteLabel = new Jlabel(); public LinkRotator() { setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE); setSize(300, 100); FlowLayout flo = new Flowlayout(); setLayout(flo); add(siteLabel); pageTitle = new String[] { "Oracle Java Site", "Server Side", "JavaWorld", "Google", "Yahoo", "Penn State" }; pageLink[0] = getUR1("http://www.oracle.com/technetwork/java");...

  • Re-write this program into a javafx program, using javafx components only. NO awt or swing. import...

    Re-write this program into a javafx program, using javafx components only. NO awt or swing. import java.awt.Button; import java.awt.Label; import java.awt.TextField; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JPanel; public class DecimalBinary { public static void main(String[] args) { JFrame frame=new JFrame(); //Create a frame frame.setTitle("Decimal-Binary Converter"); //Set its label frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 300); //Set size fo frame JPanel panel=new JPanel(); //Create a panel to contain controls frame.add(panel); //add panel to frame panel.setLayout(null); Label decimalLabel=new Label("Decimal"); //Create label for decimal decimalLabel.setBounds(10,...

  • Can you help me to link two frames in Java Swing and then if you click...

    Can you help me to link two frames in Java Swing and then if you click "Proceed button" it will link to the Second Frame...Thank you :) First frame code: //First import javax.swing.*; import java.awt.event.*; import java.io.*; public class Sample extends JFrame implements ActionListener { JMenuBar mb; JMenu file; JMenuItem open; JTextArea ta; JButton proceed= new JButton("Proceed"); Sample() { open = new JMenuItem("Open File"); open.addActionListener(this); file = new JMenu("File"); file.add(open); mb = new JMenuBar(); mb.setBounds(0, 0, 400, 20); mb.add(file); ta...

  • import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow...

    import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically 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
ADVERTISEMENT