.,'is anyone knows how to open a new frame in java?help me pls.
:'( ...i got difficulties with this one!!

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 article has been dead for over six months. Start a new discussion instead.