JAVA GUI : برنامج لايجاد ناتج الطرح او الضرب لعددين (اعداد الطالبة نغم عبده ^^)
____________________________________________________________
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author Abdo
*/
public class NewClass {
int num1 = 0;
int num2 = 0;
JFrame frame;
JPanel panel;
JTextField text;
JTextField text1;
JLabel label;
JButton sub;
JButton mult;
NewClass (){
frame = new JFrame();
GridLayout a = new GridLayout(3 ,2,18,18);
panel = new JPanel(a);
text = new JTextField();
text1 = new JTextField();
sub = new JButton("-");
mult = new JButton("X");
label = new JLabel();
label.setText(Integer.toString(num1-num2));
sub.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
num1=Integer.parseInt(text.getText());
num2=Integer.parseInt(text1.getText());
label.setText(Integer.toString(num1-num2));
}}
);
mult.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
num1=Integer.parseInt(text.getText());
num2=Integer.parseInt(text1.getText());
label.setText(Integer.toString(num1*num2));
}}
);
panel.add(text);
panel.add(text1);
panel.add(sub);
panel.add(mult);
panel.add(label);
frame.setTitle("sub & multi");
frame.add(panel);
frame.setSize(300,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setVisible(true);
}
public static void main(String[] args) {
new NewClass ();
}
}
0 التعليقات: