1. Engineering
  2. Computer Science
  3. assignment is to create a jbutton on java using swing...

Question: assignment is to create a jbutton on java using swing...

Question details

Assignment is to create a jbutton on java using swing. Every time it is clicked it switches between characters + * = %. The button also rotates 90 degrees everytime clicked as well. Posted below is my code so far, but I can only get it to switch from + to * but doesn't continue to switch after that. If possible try to edit/add-to my pre-existing code posted below, but if it's completely wrong then feel free to write up a whole new program.

import javax.swing.*;

import java.awt.event.*;

//New button for each rotated symbol?

// while loop to run through str arr

public class Button


public void createButton()


JFrame f = new JFrame("Button Example");

String str = "+";

JButton b = new JButton(str);






b.addActionListener(new ActionListener()


public void actionPerformed(ActionEvent e)


String str[] = {"+","*","=","%"};



} );



public class ButtonTest


public static void main(String[] args)


Button b = new Button();





Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution