Hi! Im new to Java and iv been studying GUI's in it. Just started with swing and tried to make this giu for a calcularot. but it doesnt execute and gives me "java.lang.NoClassDefFoundError" error. im a total noob so i cant figure it out. i'd really appreciate it someone could point out what im doing wrong here :/ ..
The following is the code:
package Calculator_gui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator_gui extends JFrame {
private JButton btns[]=new JButton[10];
private JButton signBtns[]=new JButton[4];
private JTextField result;
public Calculator_gui()
{
JPanel main_p=new JPanel(new FlowLayout());
result=new JTextField("0",12);
result.setEditable(false);
main_p.add(result);
this.setContentPane(main_p);
JPanel btpanel=new JPanel(new GridLayout(4,3)); //for numpad
for(int i=0;i<10;i++)
{
btns[i]=new JButton(i+"");
btpanel.add(btns[i]);
}
JPanel signpanel=new JPanel(new GridLayout(4,1)); //for sign buttons
signBtns[0]=new JButton("+");
signpanel.add(signBtns[1]);
signBtns[1]=new JButton("-");
signpanel.add(signBtns[2]);
signBtns[2]=new JButton("*");
signpanel.add(signBtns[3]);
signBtns[3]=new JButton("/");
signpanel.add(signBtns[3]);
this.setLayout(new BorderLayout());
this.add(main_p,BorderLayout.NORTH);
this.add(btpanel,BorderLayout.CENTER);
this.add(signpanel,BorderLayout.EAST);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setSize(200,200);
this.setTitle("Caculator");
}
public static void main(String[] args) {
// Run the GUI codes in the Event-dispatching thread for thread-safety
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Calculator_gui(); // Let the constructor do the job
}
});
}
}