Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Hello Everybody

  1. #1
    Junior Member ShakirAli's Avatar
    Join Date
    Apr 2012
    Location
    Pakistan
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Hello Everybody

    I am a new java programmer i have write a small program but it has some errors please help about this errors.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;


    public class SmallCalcApp implements ActionListener{
    JFrame frame;
    JLabel firstOperand, secondOperand, answer;
    JTextField op1, op2, ans;
    JButton plus, mul;


    // setting layout
    public void initGUI ( ) {
    frame = new JFrame();
    firstOperand = new JLabel("First Operand");
    secondOperand = new JLabel("Second Operand");
    answer = new JLabel("Answer");


    op1 = new JTextField (15);
    op2 = new JTextField (15);
    ans = new JTextField (15);
    plus = new JButton("+");
    plus.setPreferredSize(new Dimension(70,25));

    mul = new JButton("*");
    mul.setPreferredSize(new Dimension(70,25));

    Container cont = frame.getContentPane();
    cont.setLayout(new FlowLayout());
    cont.add(firstOperand);
    cont.add(op1);
    cont.add(secondOperand);
    cont.add(op2);
    cont.add(plus);
    cont.add(mul);
    cont.add(answer);
    cont.add(ans);
    plus.addActionListener(this);
    mul.addActionListener(this);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setSize(200, 220);
    frame.setVisible(true);
    }
    //constructor
    public SmallCalcApp ( ) {
    initGUI();
    }
    public void actionPerformed(ActionEvent event) {

    String oper, result;
    int num1, num2, res;

    if (event.getSource() == plus) {
    oper = op1.getText();
    num1 = Integer.parseInt(oper);
    oper = op2.getText();
    num2 = Integer.parseInt (oper);
    res = num1+num2;
    result = res+"";
    ans.setText(result);
    }
    else if (event.getSource() == mul) {
    oper = op1.getText();
    num1 = Integer.parseInt(oper);
    oper = op2.getText();
    num2 = Integer.parseInt (oper);
    res = num1*num2;
    result = res+"";
    ans.setText(result);
    }
    public static void main(String args[]) {
    SmallCalcApp scApp = new SmallCalcApp();
    }
    }// end class

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Hello Everybody

    it has some errors
    Please explain. Copy and paste here the full text of the error messages.
    If you don't understand my answer, don't ignore it, ask a question.