ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 23 Apr 2017 My Price 8.00

public class MyGUIProj

 

import java.awt.*;

import javax.swing.*;

public class MyGUIProj{

 public static void main(String[] args) {

   JFrame frame = new MyFrame(); //line 1

   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

   frame.setVisible(true);

 }

}

 

 

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class MyFrame extends JFrame {

 private JLabel resultLabel, titleLabel;

 private JButton submitButton;

 private ActionListener listener;

 private JPanel buttonPanel, labelPanel;

 private int n;

 

 public MyFrame(){

   n = 0;

   setSize(500, 500); //line 4   titleLabel = new JLabel("pushes:");   resultLabel = new JLabel("0");

   labelPanel = new JPanel();

   labelPanel.add(titleLabel);

   labelPanel.add(resultLabel);

   add(labelPanel, BorderLayout.NORTH);

 

   listener = new MyListener();   submitButton = new JButton("Push Me!");

   buttonPanel = new JPanel();

   buttonPanel.add(submitButton);

   submitButton.addActionListener(listener); //line 5

   add(buttonPanel, BorderLayout.CENTER);

 }

 class MyListener implements ActionListener {

   public void actionPerformed(ActionEvent event) {

    n += 2;

    resultLabel.setText(Integer.toString(n));

   }

 }

}

When the submitButton is pressed 3 times,

the output of

  System.out.println(resultLable.getText()); NEED HELP PLEASE

Answers

(11)
Status NEW Posted 23 Apr 2017 02:04 PM My Price 8.00

-----------

Not Rated(0)