Move button with mouse pressed
Hello guys.
I'm new here.
I have a problem with my java programming and i'm wondering if you can help.
Write a class (called W6P1.java) that will create the following interface:
3 buttons (one, two, three).
Tips:
- Set size to (300,100);
- Use FlowLayout as the layout manager
Add action listeners to the left button <one> and the right button <three> and add code to rotate the labels of the buttons every time a button is pressed. If the left button is pressed the labels rotate to the left (from <one>, <two>, <three> they will become <two>, <three>, <one>, press it again and they become <three>, <one>, <two>; press it for a third time and they become as before <one> <two> <three>.
Similar operation is required when the right button (<three>) is clicked but this time the rotation will take place right-wise.
I have done this:
Code :
import javax.swing.*; //for everything that is Jxxx
import java.awt.*; //for FlowLayout
import java.awt.event.*; //for the actionlistener
public class W6P1 extends JFrame implements ActionListener
{
private JButton btn1;
private JButton btn2;
private JButton btn3;
public W6P1()
{
super("Work6Part1");
btn1 = new JButton("One");
btn2 = new JButton("Two");
btn3 = new JButton("Three");
btn1 = new FlowLayout(FlowLayout.RIGHT);
setLayout(new FlowLayout());
add(btn1);
add(btn2);
add(btn3);
ButtonHandler handler = new ButtonHandler();
btn1.addActionListener(handler);
btn2.addActionListener(handler);
btn3.addActionListener(handler);
}
public static void main(String[] args)
{
W6P1 window = new W6P1();
window.setSize(300, 100);
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//create the inner class
private class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == btn1)
I'm really confused what to do next.
Anyone can help me?
Thanks in advance,
Stavros