Skip to content

Instantly share code, notes, and snippets.

@DScoder
Created November 18, 2013 17:05
Show Gist options
  • Save DScoder/7531403 to your computer and use it in GitHub Desktop.
Save DScoder/7531403 to your computer and use it in GitHub Desktop.
Homework14(Ended Panel realisation)
package helloCalculator;
import java.awt.*;
public class Main{
public static void main(String[] args) {
SimpleCalculator t = new SimpleCalculator("MegoCalc by DScoder");
t.setDefaultCloseOperation(t.EXIT_ON_CLOSE);
t.setBounds(100, 100, 300, 250);
t.setMinimumSize(new Dimension(250,200));
t.setVisible(true);
}
}
package helloCalculator;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
public class SimpleCalculator extends JFrame {
public SimpleCalculator(String name) {
super(name);
//Создание кросплатформенного МегоКалькулятора!
//Container(BorderLayout) = panel1(BorderLayout) + panel2(GridLayout)
Container cont = getContentPane();
cont.setLayout(new BorderLayout());
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
cont.add(panel1, BorderLayout.NORTH);
cont.add(panel2, BorderLayout.CENTER);
panel1.setLayout(new BorderLayout());
panel1.add(new JTextArea(), BorderLayout.CENTER);
JButton but = new JButton("=");
panel1.add(but, BorderLayout.EAST);
panel2.setLayout(new GridLayout(4,4,4,4));
ArrayList<JButton> buttons = new ArrayList<JButton>();
char a[] = new char[]{'+','-','*','/','1','2','3','4','5','6','7','8','9','0','.','C'};
for (int i=0; i<16; i++) {
Character c = a[i];
String d = c.toString();
buttons.add(new JButton(d));
panel2.add(buttons.get(i));
}
//Реализация технологии МегаКалькулятора!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment