Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.ComponentOrientation;
- import java.awt.Font;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Insets;
- import javax.swing.BorderFactory;
- import javax.swing.JButton;
- import javax.swing.JPanel;
- import javax.swing.JTextArea;
- public class StandardPanel extends JPanel{
- private JTextArea textArea;
- private JButton mc = new JButton("MC");
- private JButton mr = new JButton("MR");
- private JButton ms = new JButton("MS");
- private JButton mp = new JButton("M+");
- private JButton mn = new JButton("M-");
- private JButton backspace = new JButton("←");
- private JButton ce = new JButton("CE");
- private JButton c = new JButton("C");
- private JButton pm = new JButton("±");
- private JButton sqrt = new JButton("√");
- private JButton _7 = new JButton("7");
- private JButton _8 = new JButton("8");
- private JButton _9 = new JButton("9");
- private JButton div = new JButton("/");
- private JButton per = new JButton("%");
- private JButton _4 = new JButton("4");
- private JButton _5 = new JButton("5");
- private JButton _6 = new JButton("6");
- private JButton mul = new JButton("*");
- private JButton _1x = new JButton("1/x");
- private JButton _1 = new JButton("1");
- private JButton _2 = new JButton("2");
- private JButton _3 = new JButton("3");
- private JButton min = new JButton("-");
- private JButton equ = new JButton("=");
- private JButton _0 = new JButton("0");
- private JButton point = new JButton(".");
- private JButton plu = new JButton("+");
- private void setEfx() {
- Font keyfonts = new Font("Segoe UI", Font.PLAIN, 11);
- Color btncolor1 = new Color(212,224,237);
- Color btncolor2 = new Color(238,244,250);
- Color btncolor3 = new Color(237,243,248);
- textArea.setFont(new Font("Consolas", Font.PLAIN, 25));
- mc.setFont(keyfonts);
- mc.setBackground(btncolor1);
- mr.setFont(keyfonts);
- mr.setBackground(btncolor1);
- ms.setFont(keyfonts);
- ms.setBackground(btncolor1);
- mp.setFont(keyfonts);
- mp.setBackground(btncolor1);
- mn.setFont(keyfonts);
- mn.setBackground(btncolor1);
- backspace.setFont(keyfonts);
- backspace.setBackground(btncolor2);
- ce.setFont(keyfonts);
- ce.setBackground(btncolor2);
- c.setFont(keyfonts);
- c.setBackground(btncolor2);
- pm.setFont(keyfonts);
- pm.setBackground(btncolor2);
- sqrt.setFont(keyfonts);
- sqrt.setBackground(btncolor2);
- _7.setFont(keyfonts);
- _7.setBackground(btncolor3);
- _8.setFont(keyfonts);
- _8.setBackground(btncolor3);
- _9.setFont(keyfonts);
- _9.setBackground(btncolor3);
- div.setFont(keyfonts);
- div.setBackground(btncolor2);
- per.setFont(keyfonts);
- per.setBackground(btncolor2);
- _4.setFont(keyfonts);
- _4.setBackground(btncolor3);
- _5.setFont(keyfonts);
- _5.setBackground(btncolor3);
- _6.setFont(keyfonts);
- _6.setBackground(btncolor3);
- mul.setFont(keyfonts);
- mul.setBackground(btncolor2);
- _1x.setFont(keyfonts);
- _1x.setBackground(btncolor2);
- _1.setFont(keyfonts);
- _1.setBackground(btncolor3);
- _2.setFont(keyfonts);
- _2.setBackground(btncolor3);
- _3.setFont(keyfonts);
- _3.setBackground(btncolor3);
- min.setFont(keyfonts);
- min.setBackground(btncolor2);
- equ.setFont(keyfonts);
- equ.setBackground(btncolor2);
- _0.setFont(keyfonts);
- _0.setBackground(btncolor3);
- point.setFont(keyfonts);
- point.setBackground(btncolor3);
- plu.setFont(keyfonts);
- plu.setBackground(btncolor2);
- }
- public StandardPanel() {
- textArea = new JTextArea();
- setEfx();
- setBackground(new Color(217,228,241));
- textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
- textArea.setEditable(false);
- textArea.setText("0");
- textArea.setBackground(new Color(251,253,254));
- setLayout(new GridBagLayout());
- setBorder(BorderFactory.createEmptyBorder(5,4,5,4));
- GridBagConstraints gc = new GridBagConstraints();
- gc.gridx=0;//column
- gc.gridy=0;//row
- gc.weighty = 0.0;
- gc.weightx = 0.0;
- gc.ipady = 5;
- gc.ipadx = 1;
- gc.gridwidth = 5;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,0,5);//top,left,bottom,right
- add(textArea,gc);
- //-------row 1-----------
- gc.gridx=0;
- gc.gridy=1;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(mc,gc);
- gc.gridx=1;
- gc.gridy=1;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(mr,gc);
- gc.gridx=2;
- gc.gridy=1;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(ms,gc);
- gc.gridx=3;
- gc.gridy=1;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(mp,gc);
- gc.gridx=4;
- gc.gridy=1;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(mn,gc);
- //-------row 2--------
- gc.gridx=0;
- gc.gridy=2;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(backspace,gc);
- gc.gridx=1;
- gc.gridy=2;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(ce,gc);
- gc.gridx=2;
- gc.gridy=2;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(c,gc);
- gc.gridx=3;
- gc.gridy=2;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(pm,gc);
- gc.gridx=4;
- gc.gridy=2;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(sqrt,gc);
- //-------row 3--------
- gc.gridx=0;
- gc.gridy=3;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(_7,gc);
- gc.gridx=1;
- gc.gridy=3;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(_8,gc);
- gc.gridx=2;
- gc.gridy=3;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(_9,gc);
- gc.gridx=3;
- gc.gridy=3;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(div,gc);
- gc.gridx=4;
- gc.gridy=3;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(per,gc);
- //-------row 4--------
- gc.gridx=0;
- gc.gridy=4;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(_4,gc);
- gc.gridx=1;
- gc.gridy=4;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(_5,gc);
- gc.gridx=2;
- gc.gridy=4;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(_6,gc);
- gc.gridx=3;
- gc.gridy=4;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(mul,gc);
- gc.gridx=4;
- gc.gridy=4;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(_1x,gc);
- //-------row 5--------
- gc.gridx=0;
- gc.gridy=5;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(_1,gc);
- gc.gridx=1;
- gc.gridy=5;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(_2,gc);
- gc.gridx=2;
- gc.gridy=5;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(_3,gc);
- gc.gridx=3;
- gc.gridy=5;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(min,gc);
- gc.gridx=4;
- gc.gridy=5;
- gc.gridwidth = 1;
- gc.gridheight = 2;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(equ,gc);
- //-------row 6--------
- gc.gridx=0;
- gc.gridy=6;
- gc.gridwidth = 2;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(_0,gc);
- gc.gridx=2;
- gc.gridy=6;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(point,gc);
- gc.gridx=3;
- gc.gridy=6;
- gc.gridwidth = 1;
- gc.gridheight = 1;
- gc.anchor = GridBagConstraints.CENTER;
- gc.fill = GridBagConstraints.BOTH;
- gc.insets = new Insets(5,5,5,5);
- add(plu,gc);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement