diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0abed45 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "java.completion.filteredTypes": [ + "com.sun.*", + "sun.*", + "jdk.*", + "org.graalvm.*", + "io.micrometer.shaded.*" + ] +} \ No newline at end of file diff --git a/FirstGUI.java b/FirstGUI.java new file mode 100644 index 0000000..1930b4f --- /dev/null +++ b/FirstGUI.java @@ -0,0 +1,55 @@ +import javax.swing.JPanel; +import javax.swing.JFrame; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; + +import javax.swing.JButton; + +public class FirstGUI extends JPanel implements ActionListener, WindowListener { + JFrame frame; + JButton button1, button2; + public static void main(String[] args) { + new FirstGUI(); + } + public FirstGUI(){ + frame = new JFrame("FirstGUI"); + frame.setSize(300,200); + frame.getContentPane().add(this); + this.add(button1 = new JButton("Button")); + this.add(button2 = new JButton("Button2")); + button1.addActionListener(this); + button2.addActionListener(this); + frame.addWindowListener(this); + frame.setVisible(true); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + @Override + public void actionPerformed(ActionEvent e) { + System.out.println(e.getActionCommand()); + } + @Override + public void windowOpened(WindowEvent e) { + } + @Override + public void windowClosing(WindowEvent e) { + java.awt.Toolkit.getDefaultToolkit().beep(); + } + @Override + public void windowClosed(WindowEvent e) { + } + @Override + public void windowIconified(WindowEvent e) { + } + @Override + public void windowDeiconified(WindowEvent e) { + } + @Override + public void windowActivated(WindowEvent e) { + } + @Override + public void windowDeactivated(WindowEvent e) { + } +} diff --git a/Onigiri.java b/Onigiri.java new file mode 100644 index 0000000..587c492 --- /dev/null +++ b/Onigiri.java @@ -0,0 +1,73 @@ +public class Onigiri { + static int count = 0; + static void printCount(){ + System.out.println(count); + } + // フィールド/メンバ=データの詳細 + String gu ; /* おにぎりの具名 */ + boolean withNori; /* 海苔がついているか? true / false */ + int shape ; /* 0:丸, 1:俵型, 3:三角形 */ + //コンストラクタ=データ製造機 + public Onigiri() { + gu = "無し(塩むすび)"; + withNori = false; + shape = 3; + count++; + } + public Onigiri(String _gu) { + this(); + gu = _gu; + } + public Onigiri(String gu, int shape) { + this(gu); + this.shape = shape; + } + public Onigiri(String gu, boolean wnori) { + this(gu); + withNori = wnori; + } + public Onigiri(String gu, boolean wnori, int shape) { + this(gu, wnori); + this.shape = shape; + } + //メソッドの役割:(1) データの修正・更新をする (2) データに関する情報を出力 (3) データに関する処理 + public void setWithNori(boolean wnori) { + withNori = wnori; + } + public String toString() { + String str = "具は "+gu+" で、"; + switch(shape){ + case 0: + str = str+"丸型で、"; + break; + case 1: + str = str+"俵型で、"; + break; + case 3: + str = str+"三角形で、"; + break; + } + str = str + (withNori ? "海苔付き" : "海苔なし"); + return str; + } + + public static void main(String[] args) { + new Onigiri(); + //基本のおにぎりをつくる + //コンストラクタを呼び出し、インスタンスを生成 + Onigiri siomusubi = new Onigiri(); + System.out.println("siomusubi = " + siomusubi.toString()); + + Onigiri ume = new Onigiri("梅", true); + System.out.println("ume = " + ume.toString()); + + Onigiri marusake = new Onigiri("鮭", 0); + System.out.println("marusake = " + marusake.toString()); + + Onigiri mentai = new Onigiri("明太子", true, 1); + System.out.println("mentai = " + mentai.toString()); + + Onigiri.printCount(); + } +} + diff --git a/Test.java b/Test.java new file mode 100644 index 0000000..88f44b5 --- /dev/null +++ b/Test.java @@ -0,0 +1,6 @@ +class Test { + public static void main(String[] args) { + System.out.println("Test desu"); + } +} +