Question

Using the template below create a GUI with a push button event. Use a JTextArea to...

Using the template below create a GUI with a push button event. Use a JTextArea to display which button was selected.

/*******************
Name:

Date:

Notes:    
*******************/

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Actions extends JFrame implements ActionListener
{
Create the components (textarea and buttons)


   public Actions()
   {
     create the window (include a close operation)
    
  
     create the container (include FlowLayout)
    
     add the event listeners (button.addActionListener)
    
     add the components
     }
    
     public void actionPerformed(ActionEvent event)
     {
      add the event handler( if statements and event.getSource should be used here)
      }
     
      public static void main (String[] args)
      { Actions eg = new Actions(); }
      }

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

/*******************

Name:

Date:

Notes:   

*******************/

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class Actions extends JFrame implements ActionListener

{

    JTextArea ta;

    JButton b1, b2 , b3;

    public Actions()

    {

        // set the title

        setTitle("Welcome to sbi atm service");

       

        // remove the default layout

        setLayout(null);

       

        // create a panel

        JPanel p = new JPanel();

       

        // set the background color

        p.setBackground(Color.darkGray);

       

        // set the size of panel

        p.setSize(500,500);

       

        // create an object of type FlowLayout

        FlowLayout fl = new FlowLayout();

       

        // set the dimensions

        fl.setHgap(100);             

        fl.setVgap(100);

        // add the layout to panel

        p.setLayout(fl);

        // create buttons

        b1 = new JButton("Button 1");

        b2 = new JButton("Button 2");

        b3 = new JButton("Button 3");

       

        p.add(b1);

        p.add(b2);

        p.add(b3);

       

        ta = new JTextArea(5 , 20);

       

        p.add(ta);

       

        add(p);

   

        // set the ActionListener event

        b1.addActionListener(this);

        b2.addActionListener(this);

        b3.addActionListener(this);

       

        setDefaultCloseOperation(EXIT_ON_CLOSE);

        setVisible(true);

        setSize(1750,1350);

     }

   

    public void actionPerformed(ActionEvent ae)

    {

        String str = ae.getActionCommand();

       

        ta.setText(str + " is clicked");

    }

    public static void main (String[] args)

    {

        Actions eg = new Actions();

    }

}

Sample Output

Welcome to sbi atm service Button 1 Button 2 Button utton 2 is clicked

Add a comment
Know the answer?
Add Answer to:
Using the template below create a GUI with a push button event. Use a JTextArea to...
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
  • Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import...

    Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class translatorApp extends JFrame implements ActionListener {    public static final int width = 500;    public static final int height = 300;    public static final int no_of_lines = 10;    public static final int chars_per_line = 20;    private JTextArea lan1;    private JTextArea lan2;    public static void main(String[] args){        translatorApp gui = new translatorApp();...

  • Debug this java and post the corrected code. /* Creates a simple JPanel with a single...

    Debug this java and post the corrected code. /* Creates a simple JPanel with a single "quit" JButton * that ends the program when clicked. * There are 3 errors, one won't prevent compile, you have to read comments. */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class QuitIt extends JFrame {     public QuitIt() {         startIt(); //Create everything and start the listener     }     public final void startIt() {        //Create the JPanel        JPanel myPanel =...

  • 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);       ...

  • How can i make the java class seperate into an MVC pattern? public class ChatView implements Acti...

    How can i make the java class seperate into an MVC pattern? public class ChatView implements ActionListener {    public static void main(String[] args)    {        JFrame chatFrame = new JFrame();        JFrame chatFrame1 = new JFrame();        JFrame chatFrame2 = new JFrame();               JPanel chatPanel = new JPanel();        JPanel chatPanel1 = new JPanel();        JPanel chatPanel2 = new JPanel();        chatFrame.setContentPane(chatPanel);        chatFrame1.setContentPane(chatPanel1);        chatFrame2.setContentPane(chatPanel2);        chatFrame.setLayout(new FlowLayout());        chatFrame1.setLayout(new FlowLayout());        chatFrame2.setLayout(new FlowLayout());        JTextField chatWrite = new JTextField();        JTextField chatWrite1 = new JTextField();        JTextField chatWrite2 = new JTextField();        JTextArea chatDisplay...

  • 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...

  • Modify Java Code below: - Remove Button Try the Number -Instead of Try the Number button...

    Modify Java Code below: - Remove Button Try the Number -Instead of Try the Number button just hit enter on keyboard to try number -Remove Button Quit import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; // Main Class public class GuessGame extends JFrame { // Declare class variables private static final long serialVersionUID = 1L; public static Object prompt1; private JTextField userInput; private JLabel comment = new JLabel(" "); private JLabel comment2 = new JLabel(" "); private int...

  • Add a timer to the lightbulb ON/OFF program such that the bulb stays on for 10...

    Add a timer to the lightbulb ON/OFF program such that the bulb stays on for 10 seconds after the ON button is pushed and then goes off.   Put a new label on the lightbulb panel that counts the number of seconds the bulb is on and displays the number of seconds as it counts up from 0 to 10. THIS IS A JAVA PROGRAM. The image above is what it should look like. // Demonstrates mnemonics and tool tips. //********************************************************************...

  • The program below is a GUI hander for a program with the following components. private int...

    The program below is a GUI hander for a program with the following components. private int count = 0; private JLabel label; private JButton button; The handler below is for the botton. Briefly summarize what happens when the user clicks the button. public class ButtonListerner implements ActionListener {public void actionPerformed (ActionEvent e) {count ++; if (count X2 == 0) {contentPame, setBackground(color. red); label. setText ("Go");}} if (count > 10} {button .SetEnabled (false); label, setText ("ARRIVED"); contentpane. setBackground (Color. gray);}}}

  • please help me debug this Create a GUI for an application that lets the user calculate...

    please help me debug this Create a GUI for an application that lets the user calculate the hypotenuse of a right triangle. Use the Pythagorean Theorem to calculate the length of the third side. The Pythagorean Theorem states that the square of the hypotenuse of a right-triangle is equal to the sum of the squares of the opposite sides: alidate the user input so that the user must enter a double value for side A and B of the triangle....

  • 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");...

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