Simple program i created in java room reservation and cancellation.
Combination of Array, for loop and if statement. You can get more knowledge in this program. Basic program using java that gives alot of lesson to a begginer like you :-).
You can donwload my sample program below.
Download File
Wednesday, March 4, 2009
Tuesday, March 3, 2009
how to create Listbox in JAVA?
Simple program that let the user add data inside the List box using JAVA together with List, JTextField and JButton under Swing Components..
Posted by
John
Monday, March 2, 2009
Changing the background color of the JPanel using JAVA
Allows user change the color of the panel or JPanel in this program using JFrame and 3 buttons.
Posted by
John
Sample java program using JFrame, JButton and JRadioButton.
This simple program using JFrame in java allows user to multiply, Add, Subtract and Divide numbers just enter your number in the first and second text and select your operation and just simply click the button 'Show Answer' and clearing the value inside the Textbox just simply click 'Clear' button.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class JSample extends JFrame implements ActionListener {
JButton b1;
JButton b2;
JRadioButton r1;
JRadioButton r2;
JRadioButton r3;
JRadioButton r4;
JCheckBox c1;
JTextField txt1;
JTextField txt2;
public JSample() {
Container p = getContentPane();
JPanel jp = new JPanel();
ButtonGroup bg = new ButtonGroup();
p.add(jp);
bg.add(r1=new JRadioButton("Mutiplication"));
bg.add(r2=new JRadioButton("Addtion"));
bg.add(r3=new JRadioButton("Subtraction"));
bg.add(r4=new JRadioButton("Division"));
jp.add(r1);
jp.add(r2);
jp.add(r3);
jp.add(r4);
jp.add(txt1=new JTextField(5));
jp.add(txt2=new JTextField(5));
jp.add(b1=new JButton("Show Answer"));
jp.add(b2=new JButton("Clear"));
b1.addActionListener(this);
b2.addActionListener(this);
}
public static void main(String[] args) {
JSample js = new JSample();
js.setVisible(true);
js.setSize(400,100);
js.setTitle("Basic Aritmetic Operations - *, +, -, /");
js.setResizable(false);
}
public void actionPerformed(ActionEvent e) {
double ans=0.0;
JOptionPane j = new JOptionPane();
if(e.getSource() == b1) {
if(r1.isSelected()) {
ans=Double.parseDouble(txt2.getText()) * Double.parseDouble(txt1.getText());
j.showMessageDialog(null,"Answer: "+ ans);
}else if(r2.isSelected()) {
ans=Double.parseDouble(txt2.getText()) + Double.parseDouble(txt1.getText());
j.showMessageDialog(null,"Answer: "+ ans);
}else if(r3.isSelected()) {
ans=Double.parseDouble(txt2.getText()) - Double.parseDouble(txt1.getText());
j.showMessageDialog(null,"Answer: "+ ans);
}else if(r4.isSelected()) {
ans=Double.parseDouble(txt2.getText()) / Double.parseDouble(txt1.getText());
j.showMessageDialog(null,"Answer: "+ ans);
}else {
j.showMessageDialog(null,"Select first Operation","Error",JOptionPane.ERROR_MESSAGE);
txt1.setText("");
txt2.setText("");
}
}else if(e.getSource() == b2) {
txt1.setText("");
txt2.setText("");
}
}
}
You can download my example below.
Download File
Download File
Posted by
John
Subscribe to:
Posts (Atom)