Question: package edu.buffalostate.cis 4 2 5 . sp 2 4 . put - your - username - here; / * * * File: MeFirstPanel.java * *

package edu.buffalostate.cis425.sp24.put-your-username-here;
/**
* File: MeFirstPanel.java
*
* Description: This class defines a GUI in a JPanel which contains
* two JButton with initial labels "Me first!" and "Me next!".
* Pressing either button causes the labels to be exchanged.
*
* Requirements
*1) Add a third button to the panel, with the label "third"
*2) Every time any of the buttons are pressed, the labels
* should shift one place to the right first->second->third
* would shift to third->first->second when one of the buttons
* was pressed
*/
/**
*
* @author put-your-name-here
*
*/
import javax.swing.*;
import java.awt.event.*;
public class MeFirstPanel extends JPanel implements ActionListener {
private JButton aButton;
private JButton bButton;
// add button here
String aText = "first";
String bText = "second";
// add string here
String tempText; // To use to exchange labels
public MeFirstPanel(){
aButton = new JButton(aText);
aButton.addActionListener(this); // add event handler
bButton = new JButton(bText);
bButton.addActionListener(this); // add event handler
add(aButton); // add button to JPanel
add(bButton); // add button to JPanel
}// End MeFirstPanel()
/**
* actionPerformed
* @param e button clicked
*/
public void actionPerformed(ActionEvent e){
tempText = aText; // Exchange the strings
aText = bText;
bText = tempText;
// add code here
aButton.setText(aText); // Set button labels
bButton.setText(bText);
// add code here
}// EndactionPeformed()
}// End MeFirstPanel class
package edu.buffalostate.cis425.fa21.exercises.put-your-lastname-here;
/**
* File: MeFirstApp.java
*
* Description: This app creates a MeFirstPanel and
* adds it to the app's content pane.
*
* Assignment: see MeFirstPanel.java
*
*/
/**
*
* @author put-your-name-here
*
*/
import javax.swing.*;
public class MeFirstApp extends JFrame {
private static final long serialVersionUID =1L;
public MeFirstApp(){
setSize(200,200);
getContentPane().add(new MeFirstPanel());
//register 'Exit upon closing' as a default close operation
setDefaultCloseOperation( EXIT_ON_CLOSE );
}// End MeFirstApp
public static void main(String args[]){
MeFirstApp b = new MeFirstApp();
b.setVisible(true);
}// End main()
}// End MeFirstApp class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!