~cpp public class FirstJava { public static void main(String argv[]) { System.out.println("Hello world!"); } }
~cpp import javax.swing.*; public class FirstJava extends JFrame{ public FirstJava() { } public static void main(String args[]) { FirstJava helloWorld = new FirstJava(); helloWorld.setBounds(100,100,800,600); helloWorld.show(); } }
~cpp package WindowFrame; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import javax.swing.JFrame; public class WindowFrame { static BufferedReader breader; public WindowFrame(String title, int width, int height) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(width, height); f.show(); } public static int inputInt() throws IOException { breader = new BufferedReader(new InputStreamReader(System.in)); return Integer.parseInt(breader.readLine()); } public static String inputString() throws IOException { return breader.readLine(); } public static void main(String[] args) { breader = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("윈도우 이름 : "); String title = inputString(); System.out.print("넓이 : "); int w = inputInt(); System.out.print("높이 : "); int h = inputInt(); new WindowFrame(title, w, h); } catch(IOException ex) { ex.printStackTrace(); } } }
~cpp import java.awt.Graphics; import javax.swing.*; public class FirstJava extends JFrame{ public FirstJava() { } public static void main(String args[]) { FirstJava helloWorld = new FirstJava(); helloWorld.setBounds(100,100,800,600); helloWorld.show(); } public void paint(Graphics g) { g.drawLine(100,100,300,300); g.drawOval(200,200,400,400); g.fillOval(500,500,100,100); } }
~cpp import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.*; public class FirstJava extends JFrame{ public FirstJava() { addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int x = e.getX(); int y = e.getY(); System.out.println("x 좌표 : " + x); System.out.println("y 좌표 : " + y); } }); } public static void main(String args[]) { FirstJava helloWorld = new FirstJava(); helloWorld.setBounds(100,100,800,600); helloWorld.show(); } }
~cpp import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.*; public class FirstJava extends JFrame{ public FirstJava() { addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int x = e.getX(); int y = e.getY(); repaint(); } }); } public static void main(String args[]) { FirstJava helloWorld = new FirstJava(); helloWorld.setBounds(100,100,800,600); helloWorld.show(); } public void paint(Graphics g) { System.out.print("Click!! "); } }
~cpp 6 0 0 222244451 999 Output 1 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 2 0 0 0 0 1 0 0 0 0 0 0 0 0 5 0 0 22224444346 999 Output 2 1 1 1 1 1 0 0 0 2 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 3 0 0 44220064 999 Output 1 1 1 1 1 1 1 1 1
~cpp from StarCraft import StarCraft sc = StarCraft () dir(sc) gateway = sc.createGateway () dir(gateway) z1 = gateway.createZealot () dir(z1) z1.move (160,160) d1 = gateway.createDragoon () dir(d1) d1.move (180,180) z1.printHp() z1.getPosition() d1.printHp() d1.getPosition() z1.setAttackTarget(d1) z1.printAttackTarget() z1.getAttackTarget().printHp() z1.getAttackTarget().getPosition() z1.attack() d1.printHp()