3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by TheWhite
0

extend JFrame to your class and then you can do some work...

If you want an example, you can probably use this to get you started:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;


public class test extends JFrame {
	public boolean mouseClick = false;
	
	public static void main(String[] args){
		SwingUtilities.invokeLater(new Runnable() {
			public void run(){
				new test();
			}
		});
	}

	private test(){
		super("test");
		launch();
	}
	
	private void launch(){
		setBounds(100, 100, 100,75);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
                
        JButton b = new JButton("Test Me");
		b.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae){				
					performClickAction((JButton)ae.getSource());
			}
		});

		JPanel p = new JPanel();
		p.add(b);
		setContentPane(p);
		setVisible(true);
	}


	private void performClickAction(JButton b){
		b.setText("Ouch!");
	}
}

This will actually create a little JFrame with a JButton that says "Ouch!" when you click it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.