import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.awt.event.*;
class MyMatching extends JFrame
{
final JTextField txt1=new JTextField("Name1",10);
JLabel lbl3=new JLabel("Love");
final JTextField txt2=new JTextField("Name2",10);
JButton btn=new JButton("Result");
JTextField txt3=new JTextField("%",5);
JTextArea ta=new JTextArea(10,40);
JPanel pnl1=new JPanel();
JPanel pnl2=new JPanel();
MyInner inner;
MyMatching()
{
setupGUI();
}
private void setupGUI()
{
setSize(500,300);
setTitle("Love Matching v1");
Container c=getContentPane();
c.setLayout(new BorderLayout());
pnl1.setLayout(new FlowLayout());
pnl1.add(txt1);
pnl1.add(lbl3);
pnl1.add(txt2);
pnl1.add(btn);
pnl1.add(txt3);
pnl2.add(ta);
c.add("North",pnl1);
c.add("Center",pnl2);
setVisible(true);
inner=new MyInner ();
btn.addActionListener( inner);
}
}
class MyInner implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(!txt1.getText().equals("Name1") && !txt2.getText().equals("Name2"))
{
if (e.getActionCommand().equals("Result"))
{
//First process
int random= ((int)(50*Math.random()))+50;
txt3.setText(random+"%");
//second process
String msg[ ]={"Love Can Touch Us One Time And Last For The Life Time\nYou Are A True Lovers.","Your Feelings Are Different \nYou Should Forget it."
,"Love Is A Passion\nYou Must Be More Romantic.","You Are An Angel\n But Your Lover Is A Liar."
,"You Must Think Deeply Before That Choice\nLove Is Not An Entertainment.","Do Not Lie To Your Hart\nYou Still Love Your First Lover."
,"You Cannot Love Again\nYour First Lover is So Lovely And Cannot Be Forotten."};
ta.setText( msg[((int)( msg.length*Math.random()))] );
/* breaking up the code
double random = Math.random();
int index = (int) (msg.length*random);
String message = msg[index];
ta.setText(message);*/
ta.setForeground(Color.RED);
}
else
{
MyFrame2.this.c2.setSelected(true);
}
}
}
}
class MyFrame2 extends JFrame
{
ImageIcon img=new ImageIcon("D:\\Mastering Java\\Java Projects\\Icons\\alert_lrg.gif ");
JLabel lbl=new JLabel(" You Must Enter A Name!",img,JLabel.LEFT);
JPanel pnl3=new JPanel();
MyFrame2()
{
setupgui();
}
private void setupgui()
{
setSize(220,130);
setTitle("Error");
Container c2=getContentPane();;
pnl3.setLayout(new BorderLayout());
lbl.setIcon(img);
pnl3.add("Center",lbl);
c2.add(pnl3);
setVisible(true);
}
}
public static void main(String[]args)
{
MyMatching mtch=new MyMatching();
MyFrame2 frm=new MyFrame2();
}
so sir here how can i organize my classes
here i have 4 classes
1-class MyMatching //containing the first frame
2-class MyFrame2//containing the second frame
3-class MyInner //containing listeners for the two prevoius classes
4-the main class
****in the inner class i have to use objects from the first two classe***
what would be the approbriate organization for the classes?
who contains other?
thank you all