Last active
October 31, 2015 09:48
-
-
Save itochan/4888a76b39a556c7b632 to your computer and use it in GitHub Desktop.
OOP2015 Assignment No.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Ex2_4_1 | |
* | |
* Copyright (c) 2015 Kazunori Jo | |
* | |
* This software is released under the MIT License. | |
* http://opensource.org/licenses/mit-license.php | |
*/ | |
import java.awt.BorderLayout; | |
import javax.swing.ImageIcon; | |
import javax.swing.JButton; | |
import javax.swing.JFrame; | |
public class Ex2_4_1 { | |
public static void main(String argv[]) { | |
JFrame window = new JFrame("Hello World!"); | |
ImageIcon icon = new ImageIcon("src/yakiniku.jpg"); | |
JButton button = new JButton(icon); | |
window.add(button, BorderLayout.CENTER); | |
window.pack(); | |
window.setVisible(true); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Ex2_4_2 | |
* | |
* Copyright (c) 2015 Kazunori Jo | |
* | |
* This software is released under the MIT License. | |
* http://opensource.org/licenses/mit-license.php | |
*/ | |
import java.awt.BorderLayout; | |
import java.awt.GridLayout; | |
import javax.swing.JButton; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
import javax.swing.JTextField; | |
public class Ex2_4_2 { | |
public static void main(String argv[]) { | |
JFrame window = new JFrame("Calculator"); | |
JTextField text = new JTextField(); | |
text.setText("0"); | |
window.add(text, BorderLayout.NORTH); | |
JPanel panel = new JPanel(); | |
panel.setLayout(new GridLayout(4, 4)); | |
String[] labels = { | |
"1", "2", "3", "+", | |
"4", "5", "6", "-", | |
"7", "8", "9", "*", | |
"0", ".", "=", "/" | |
}; | |
for (String label : labels) { | |
JButton button = new JButton(label); | |
panel.add(button, BorderLayout.CENTER); | |
} | |
window.add(panel, BorderLayout.SOUTH); | |
window.pack(); | |
window.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment