Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LANGUAGE: JAVA Created a GUI, not showing. I believe I need to create another class but I am lost. Please explain anyhting added on to

LANGUAGE: JAVA

Created a GUI, not showing. I believe I need to create another class but I am lost. Please explain anyhting added on to the code.

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JTextField;

import java.awt.Color;

public class MyNamePlease extends JPanel implements ActionListener{ private JButton identityButton; private JLabel titleDisplay; private JTextField firstName; private JTextField lastName; public MyNamePlease() { setBackground(Color.green); titleDisplay = new JLabel ("Name Please!"); firstName = new JTextField(5); lastName = new JTextField(7); identityButton = new JButton ("OK"); identityButton.addActionListener(this); add(identityButton); add(titleDisplay); } @Override public void actionPerformed (ActionEvent A) { titleDisplay.setText("Clicked"); } }

TESTER

import java.awt.GridLayout;

import javax.swing.JFrame;

public class tester extends JFrame{ public static void main (String[]args) { }

public tester() { MyNamePlease A1 = new MyNamePlease(); add(A1); setLayout(new GridLayout(2,1)); setSize(200,100); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE);

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions