seems i was not clear ...
this is the code
and i want when i press the "about"
a message like a jdialoge or joptionpane appears
my problems:
1-i do not no how the action event will be
like public void actionperformed(action event e )
2-i do not no where to put this class
the code
import java.awt.*;
import java.awt.Toolkit;
import java.awt.Image;
import java.awt.Point;
import java.awt.Cursor;
import javax.swing.*;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.AbstractButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.net.URL;
import java.io.*;
import java.awt.event.*;
public class MyMatching extends JFrame
{
final JTextField txt1=new JTextField("Name1",10);
JLabel lbl3=new JLabel("Love");
final JTextField txt2=new JTextField("Name2",10);
ImageIcon img =new ImageIcon("D:\\Other\\JAVA\\Icons\\heart7.png");
JButton btn = new JButton("Result", img);
JTextField txt3=new JTextField("%",5);
JTextArea ta=new JTextArea(10,40);
JTabbedPane tp = new JTabbedPane();
int location = JTabbedPane. LEFT;
//Get the default toolkit
Toolkit toolkit = Toolkit.getDefaultToolkit();
//Load an image for the cursor
Image cursorImage = toolkit.getImage("D:\\Other\\JAVA\\Icons\\heart7.png");
//Create the hotspot for the cursor
Point cursorHotSpot = new Point(0,0);
//Create the custom cursor
Cursor customCursor = toolkit.createCustomCursor(cursorImage, cursorHotSpot, "heart7");
JLabel lbl4=new JLabel("This Simple Project Was Made By Mahmoud Saleh");
JPanel pnl1=new JPanel();
JPanel pnl2=new JPanel();
JPanel pnl3=new JPanel();
MyInner inner;
MyMatching()
{
setupGUI();
}
private void setupGUI()
{
Container c=getContentPane();
setTitle("Love matcing");
setSize(550,350);
c.setLayout(new BorderLayout());
pnl1.setLayout(new FlowLayout());
pnl1.add(txt1);
pnl1.add(lbl3);
pnl1.add(txt2);
pnl1.add(btn);
pnl1.add(txt3);
pnl1.add(ta);
// pnl2.add(ta);
String label = "About";
tp.addTab(label, pnl3);
c.add("North",tp);
c.add("Center",pnl1);
// c.add("West",pnl2);
btn.setVerticalTextPosition(AbstractButton.BOTTOM);
btn.setHorizontalTextPosition(AbstractButton.CENTER);
btn.setToolTipText("Display The Result.");
ta.setBackground(Color.cyan);
setVisible(true);
//Use the custom cursor
c.setCursor(customCursor);
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"))
{
int random= ((int)(50*Math.random()))+50;
txt3.setText(random+"%");
if(random>=50&&random<80)
{
String msg[ ]={"xx","yy","zz"
};
ta.setText( msg[((int)( msg.length*Math.random()))]);
}
else if(random>80&&random<=100)
{
String msg2[ ]={"aa","bb","cc"
};
ta.setText( msg2[((int)( msg2.length*Math.random()))]);
}
ta.setForeground(Color.RED);
}
}
else
{
Toolkit tk = Toolkit.getDefaultToolkit();
tk.beep();
JOptionPane.showMessageDialog(null, "You Must Enter A Name! " );
//System.exit(0);
}
}
}
public static void main(String[]args)
{
MyMatching mtch=new MyMatching();
}
}