import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
public class MainFrame extends JFrame implements ActionListener{
private JPanel contentPane;
private JLabel mainLable = null;
private JLabel bitLable = null;
private JRadioButton Hex = null;
private JRadioButton Dec = null;
private JRadioButton Oct = null;
private JRadioButton Bin = null;
private JRadioButton Qword = null;
private JRadioButton Dword= null;
private JRadioButton Word= null;
private JRadioButton Byte= null;
private JButton btnQout = null;
private JButton Mod = null;
private JButton A = null;
private JButton B = null;
private JButton button_del = null;
private JButton CE = null;
private JButton C2 = null;
private JButton PAN= null;
private JButton C = null;
private JButton Seven = null;
private JButton Eight = null;
private JButton Nine = null;
private JButton Division = null;
private JButton D = null;
private JButton Four = null;
private JButton Five = null;
private JButton Six = null;
private JButton Mul = null;
private JButton E = null;
private JButton One = null;
private JButton Two = null;
private JButton Three = null;
private JButton Sub = null;
private JButton equal = null;
private JButton F = null;
private JButton Zero = null;
private JButton Add = null;
Stack<Integer> numStack = new Stack();
Stack<Integer> symbol = new Stack();
int currentInteger;
boolean newNum = true;
StringBuffer nowNum = new StringBuffer("0");
List<String> expression = new ArrayList<String>();
String Progressive = "Dec";
String s = "0000000000000000000000000000000000000000000000000000000000000000";
/**
* Launch the application.
*/
public ButtonGroup g=new ButtonGroup();
public ButtonGroup g1=new ButtonGroup();
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainFrame frame = new MainFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
void showBitLableText(String n){
if("Hex".equals(Progressive)) n = Integer.toBinaryString(Integer.valueOf(n,16));
else if("Dec".equals(Progressive)) n = Integer.toBinaryString(Integer.parseInt(n));
else if("Oct".equals(Progressive)) n = Integer.toBinaryString(Integer.valueOf(n,8));
StringBuffer sf = new StringBuffer(s);
for(int i=n.length()-1,j = s.length()-1;i>=0;i--,j--){
sf.setCharAt(j, n.charAt(i));
}
s = sf.toString();
String bitLableText = "<html>"
+ s.substring(0,4)+"             "+s.substring(4,8)+"             "+s.substring(8,12)+"             "+s.substring(12,16)+"             "+s.substring(16,20)+"             "+s.substring(20,24)+"             "+s.substring(24,28)+"             "+s.substring(28,32)+"<br/>"
+ "63                                                                                     47                                                                   32<br/>"
+ s.substring(32,36)+"             "+s.substring(36,40)+"             "+s.substring(40,44)+"             "+s.substring(44,48)+"             "+s.substring(48,52)+"             "+s.substring(52,56)+"             "+s.substring(56,60)+"             "+s.substring(60,64)+"<br/>"
+ "31                                                                                     15                                                                     0"
+ "</html>";
bitLable.setText(bitLableText);
s = "0000000000000000000000000000000000000000000000000000000000000000";
}
public MainFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 530, 430);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
mainLable = new JLabel(nowNum.toString(),SwingConstants.RIGHT);
mainLable.setFont(new Font("Calibri", Font.PLAIN, 22));
mainLable.setBounds(10, 10, 501, 32);
contentPane.add(mainLable);
bitLable = new JLabel("");
bitLable.setBounds(10, 52, 501, 82);
contentPane.add(bitLable);
showBitLableText("0");
Hex = new JRadioButton("Hex");
Hex.setBounds(10, 140, 80, 23);
contentPane.add(Hex);
Hex.addActionListener(this);
Dec = new JRadioButton("Dec");
Dec.setBounds(10, 170, 80, 23);
contentPane.add(Dec);
Dec.setSelected(true);
Dec.addActionListener(this);
Oct = new JRadioButton("Oct");
Oct.setBounds(10, 200, 80, 23);
contentPane.add(Oct);
Oct.addActionListener(this);
Bin = new JRadioButton("Bin");
Bin.setBounds(10, 230, 80, 23);
contentPane.add(Bin);
Bin.addActionListener(this);
g.add(Hex);
g.add(Dec);
g.add(Oct);
g.add(Bin);
Qword = new JRadioButton("Qword");
Qword.setBounds(10, 280, 80, 23);
contentPane.add(Qword);
Qword.setSelected(true);
Dword = new JRadioButton("Dword");
Dword.setBounds(10, 310, 80, 23);
contentPane.add(Dword);
Word = new JRadioButton("Word");
Word.setBounds(10, 340, 80, 23);
contentPane.add(Word);
Byte = new JRadioButton("Byte");
Byte.setBounds(10, 370, 80, 23);
contentPane.add(Byte);
g1.add(Qword);
g1.add(Dword);
g1.add(Word);
g1.add(Byte);
btnQout = new JButton("Quot");
btnQout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
expression.add(nowNum.toString());
expression.add("quot");
nowNum.delete(0, nowNum.length());
nowNum.append(0);
}
});
btnQout.setFont(new Font("Calibri", Font.PLAIN, 8));
btnQout.setBounds(96, 137, 51, 40);
contentPane.add(btnQout);
JButton Mod = new JButton("Mod");
Mod.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
expression.add(nowNum.toString());
expression.add("%");
newNum = true;
}
});
Mod.setFont(new Font("Calibri", Font.PLAIN, 8));
Mod.setBounds(148, 137, 51, 40);
contentPane.add(Mod);
A = new JButton("A");
A.addActionListener(this);
A.setEnabled(false);
A.setFont(new Font("Calibri", Font.PLAIN, 9));
A.setBounds(200, 137, 51, 40);
contentPane.add(A);
JButton MC = new JButton("MC");
MC.setFont(new Font("Calibri", Font.PLAIN, 9));
MC.setBounds(252, 137, 51, 40);
MC.setEnabled(false);
contentPane.add(MC);
JButton MR = new JButton("MR");
MR.setFont(new Font("Calibri", Font.PLAIN, 9));
MR.setBounds(304, 137, 51, 40);
MR.setEnabled(false);
contentPane.add(MR);