السلام عليكم .... بليز ممكن مساعده انا سويت برنامجي بس ناقصه 3 اشياء اول شي ابغى L1 يكون بأعلى الفريم بختيارadd(p1,BorderLayout.NORTH);
و b6 add(p2,BorderLayout.SOUTH);
حاولت فيه اني اخلي L1شمال وb6 جنوب بس ماضبط..
ابغى طريقه استخدم فيها button(Clear يمسح T1,T2,T3,T4
وشكرا"
احتاج البرنامج اليوم لان بكرا التسليم الله يجزاكم خير لا تنسوني اختكم بالاسلام
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
public class frameee extends JFrame implements ActionListener
{
JTextField T1,T2,T3,T4;
public frameee()
{
JLabel L1=new JLabel("This Program Works as calculator");
JLabel L2=new JLabel("Numbers");
JLabel L3=new JLabel("=");
T1=new JTextField(10);
T2=new JTextField(10);
T3=new JTextField(10);
T4=new JTextField(10);
JButton b1=new JButton("Add");
JButton b2=new JButton("Subtract");
JButton b3=new JButton("Multiple");
JButton b4=new JButton("Divide");
JButton b5=new JButton("RESULT");
JButton b6=new JButton("END");
JPanel p1=new JPanel();
JPanel p2=new JPanel();
add(p1,BorderLayout.NORTH);
add(p2,BorderLayout.SOUTH);
FlowLayout flo=new FlowLayout();
Font f=new Font("Arial",Font.BOLD,18);
setLayout(flo);
p1.add(L1);
add(L2);
add(T1);
add(T2);
add(L3);
add(T3);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(T4);
p2.add(b6);
b1.setFont(f);
b2.setFont(f);
b3.setFont(f);
b4.setFont(f);
b5.setFont(f);
b6.setFont(f);
L1.setForeground(Color.MAGENTA);
L2.setForeground(Color.GRAY);
L3.setForeground(Color.DARK_GRAY);
b1.setForeground(Color.BLUE);
b2.setForeground(Color.CYAN);
b3.setForeground(Color.ORANGE);
b4.setForeground(Color.YELLOW);
b5.setForeground(Color.LIGHT_GRAY);
b6.setForeground(Color.RED);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String a=ae.getActionCommand();
if(a.equals("Add"))
{
double n1=Double.parseDouble(T1.getText());
double n2=Double.parseDouble(T2.getText());
double b=n1+n2;
T3.setText(Double.toString(b));
}
else if(a.equals("Subtract"))
{
double n1=Double.parseDouble(T1.getText());
double n2=Double.parseDouble(T2.getText());
double b=n1-n2;
T3.setText(Double.toString(b));
}
else if(a.equals("Multiple"))
{
double n1=Double.parseDouble(T1.getText());
double n2=Double.parseDouble(T2.getText());
double b=n1*n2;
T3.setText(Double.toString(b));
}
else if(a.equals("Divide"))
{
double n1=Double.parseDouble(T1.getText());
double n2=Double.parseDouble(T2.getText());
double b=n1/n2;
T3.setText(Double.toString(b));
}
else if(a.equals("RESULT"))
{
double b=Double.parseDouble(T3.getText());
if(b<0)
T4.setText("NEGATIVE");
else
T4.setText("POSITIVE");
}
else
System.exit(0);
}
public static void main(String args[])
{
frameee one=new frameee();
one.setVisible(true);
one.setSize(400,230);
one.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}