Skip to content

Instantly share code, notes, and snippets.

@Blasanka
Last active June 6, 2017 16:50
Show Gist options
  • Save Blasanka/f6b9a5c2eb43d9a19dfa4f0e75f757ad to your computer and use it in GitHub Desktop.
Save Blasanka/f6b9a5c2eb43d9a19dfa4f0e75f757ad to your computer and use it in GitHub Desktop.
This is the main file(Example.java) and the second class called "ChildExample.java". Both are in this file you have to divide to two java files.
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Example {
private JFrame frame;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Example window = new Example();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Example() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton btnClicked = new JButton("Clicked");
//ChildExample obj=new ChildExample();
btnClicked.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
ChildExample obj=new ChildExample();
//obj.getJavaProject2_28();
}
});
btnClicked.setBounds(150, 99, 89, 23);
frame.getContentPane().add(btnClicked);
}
}
//-------------------------------------------------------Second class--------------------------------------------------------
import java.awt.EventQueue;
import javax.swing.JFrame;
public class ChildExample {
private JFrame frame;
// public static void main(String[] args) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// ChildExample window = new ChildExample();
// window.frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// }
public ChildExample() {
initialize();
}
public void getJavaProject2_28()
{
frame.setVisible(true);
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
@Blasanka
Copy link
Author

Blasanka commented Jun 6, 2017

Have any problem leave a comment here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment