diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b44f817 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.DS_Store +*.jar +*.class + +*.lst + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ff061dd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ], + "java.completion.filteredTypes": [ + "com.sun.*", + "sun.*", + "jdk.*", + "org.graalvm.*", + "io.micrometer.shaded.*" + ] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..7c03a53 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/src/App.java b/src/App.java new file mode 100644 index 0000000..a8b2ba1 --- /dev/null +++ b/src/App.java @@ -0,0 +1,12 @@ +import mypackage.Test; + +public class App { + public static void main(String[] args) throws Exception { + System.out.println("Hello, World!"); + + Test test = new Test(); + mypackage.subpack.Sub sub = new mypackage.subpack.Sub(); + + System.out.println(Onigiri.count+" "+Onigiri.all.size()); + } +} diff --git a/src/FirstGUI.java b/src/FirstGUI.java new file mode 100644 index 0000000..fa1bf80 --- /dev/null +++ b/src/FirstGUI.java @@ -0,0 +1,44 @@ +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JFrame; + +class MyJButton extends JButton implements ActionListener { + public MyJButton(String label){ + super(label); + } + public Dimension getPreferredSize(){ + return new Dimension(300, 100); + } + @Override + public void actionPerformed(ActionEvent e) { + FirstGUI.jf.pack(); + System.out.println(e.getActionCommand()); + } +} + +public class FirstGUI { + static JFrame jf; + public static void main(String[] args){ + System.out.println("FirstGUI"); + + jf = new JFrame("FirstGUI"); + + MyJButton jb = new MyJButton("Label Label Label"); + jb.addActionListener(jb); + jb.addActionListener( e -> System.out.println("Button was pressed") ); + // jb.addActionListener(new ActionListener() { + // @Override + // public void actionPerformed(ActionEvent e) { + // JOptionPane.showMessageDialog(jb,"Button was pressed."); + // } + // }); + jf.getContentPane().add(jb); +// jf.setSize(300,200); + jf.pack(); + jf.setVisible(true); + jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } +} diff --git a/src/Onigiri.java b/src/Onigiri.java new file mode 100644 index 0000000..66321ac --- /dev/null +++ b/src/Onigiri.java @@ -0,0 +1,95 @@ +import java.util.ArrayList; + +class NikumakiOnigiri extends Onigiri { + String niku; + NikumakiOnigiri(String _niku){ + niku = _niku; + } + void aburu(){ + + } + +} + +public class Onigiri /*extends Object*/ { + static int count = 0; //いくつ作ったかをカウントするクラス変数 + static ArrayList all = new ArrayList(); + static void printAll(){ + for(Onigiri o: all){ + System.out.println(o.toString()); + } + } + + // フィールド/メンバ=データの詳細 + String gu ; /* おにぎりの具名 */ + boolean withNori; /* 海苔がついているか? true / false */ + int shape ; /* 0:丸, 1:俵型, 3:三角形 */ + + //コンストラクタ=データ製造機 + public Onigiri() { + gu = "無し(塩むすび)"; + withNori = false; + shape = 3; + Onigiri.count++; // おにぎりの型についているカウンタを増やす + Onigiri.all.add(this); + } + 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; + } // Overload + 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 boolean toString(String a){ + // return false; + // } + // Override XX Overwrite + 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) { + //基本のおにぎりをつくる + //コンストラクタを呼び出し、インスタンスを生成 + Onigiri siomusubi = new Onigiri(); + System.out.println("siomusubi = " + siomusubi.toString()); + Onigiri.all.add(siomusubi); + + 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()); + + System.out.println("作ったおにぎりの総数は:"+count+"個"); + } +} diff --git a/src/mypackage/Test.java b/src/mypackage/Test.java new file mode 100644 index 0000000..ed7166b --- /dev/null +++ b/src/mypackage/Test.java @@ -0,0 +1,5 @@ +package mypackage; + +public class Test { + +} diff --git a/src/mypackage/subpack/Sub.java b/src/mypackage/subpack/Sub.java new file mode 100644 index 0000000..70925c7 --- /dev/null +++ b/src/mypackage/subpack/Sub.java @@ -0,0 +1,6 @@ +package mypackage.subpack; + +public class Sub { + + +}