Last active
June 6, 2017 16:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have any problem leave a comment here.