I have a problem with compiling. If I compile my code, it creates a GUI.class and GUI$x.class, wehere x stands for the amount of buttons I put in ( that means, if i have two buttons it creates a GUI$1.class and a GUI$2.class). The shown GUI is correct and works fine. Why does it create those $.class files and how can i correct it? Here is a code snippet:
public class GUI implements ActionListener,ListSelectionListener,FocusListener {
static DefaultListModel<String> inputHistory;
static DefaultListModel<String> resultHistory;
static JTextField input;
JList<String> listInput;
JList<String> listResult;
static JLabel status;
JButton enter;
JButton delete;
JButton copy;
JButton paste;
static JButton numpad;
boolean keyboardActivated = true;
public GUI() {
JFrame frame = new JFrame("calc");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setSize(705, 400);
frame.getContentPane().setLayout(null);
input = new JTextField();
input.setBounds(10,10,560,50);
input.setActionCommand("input");
input.addActionListener(this);
enter = new JButton("=");
enter.setBounds(580,10,100,50);
enter.addActionListener(this);
delete = new JButton("C");
delete.setBounds(580,90,100,50);
delete.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
input.setText("");
}
});
copy = new JButton("copy");
copy.setBounds(580,150,100,50);
copy.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Toolkit.getDefaultToolkit().getSystemClipboard().setContents (
new StringSelection(input.getText()), null
);
}
});
paste = new JButton("paste");
paste.setBounds(580,210,100,50);
paste.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
DataFlavor flavor = DataFlavor.stringFlavor;
if (clipboard.isDataFlavorAvailable(flavor)) {
try {
String text = (String) clipboard.getData(flavor);
input.setText(text);
} catch (UnsupportedFlavorException f) {
System.out.println(f);
} catch (IOException f) {
System.out.println(f);
}
}
}
});
JLabel label1 = new JLabel("input history");
label1.setBounds(10, 70, 200, 20);
inputHistory = new DefaultListModel<>();
listInput = new JList<>(inputHistory);
listInput.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
listInput.addListSelectionListener(this);
listInput.addFocusListener(this);
JScrollPane sp = new JScrollPane();
sp.setViewportView(listInput);
sp.setBounds(10,90,280,250);
JLabel label2 = new JLabel("result history");
label2.setBounds(290,70,280,20);
resultHistory = new DefaultListModel<>();
listResult = new JList<>(resultHistory);
listResult.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
listResult.addListSelectionListener(this);
listResult.addFocusListener(this);
JScrollPane sp1 = new JScrollPane();
sp1.setViewportView(listResult);
sp1.setBounds(290,90,280,250);
status = new JLabel("");
status.setForeground(Color.red);
status.setBounds(10,340,650,20);
numpad = new JButton("Numpad");
numpad.setBounds(580,290,100,50);
numpad.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new Numpad();
numpad.setEnabled(false);
}
});
frame.getContentPane().add(input);
frame.getContentPane().add(enter);
frame.getContentPane().add(label1);
frame.getContentPane().add(label2);
frame.getContentPane().add(sp);
frame.getContentPane().add(sp1);
frame.getContentPane().add(status);
frame.getContentPane().add(numpad);
frame.getContentPane().add(delete);
frame.getContentPane().add(copy);
frame.getContentPane().add(paste);
frame.setVisible(true);
}
public static void main(String[] args) {
new GUI();
}
public void actionPerformed(ActionEvent e) {
String result = null;
try {
result = Postfix.eval(input.getText());
} catch (Exception ex) {
status.setText(ex.getMessage());
}
if (result != null) {
inputHistory.insertElementAt(input.getText(), 0);
resultHistory.insertElementAt(result , 0);
input.setText(result);
input.setCaretPosition(0);
status.setText("");
}
}
}