Head First Java
文章平均质量分 50
「已注销」
这个作者很懒,什么都没留下…
展开
-
final in Java DEMO
class Dog { int size;}public class Test { public static void main(String[] args) { final Dog dog = new Dog(); dog.size = 100; System.out.println(dog.size);原创 2015-07-27 11:57:58 · 366 阅读 · 0 评论 -
JTextArea DEMO
package HeadFirstJava;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class TextArea1 implements ActionListener { JTextArea text; public static void main(Strin转载 2015-07-29 08:36:24 · 677 阅读 · 0 评论 -
serialization DEMO
package HeadFirstJava;import java.io.*;@SuppressWarnings("serial")public class Box implements Serializable { @SuppressWarnings("unused") private int width; @SuppressWarnings("unused")转载 2015-07-29 09:21:50 · 384 阅读 · 0 评论 -
box layout DEMO
package HeadFirstJava;import javax.swing.*;import java.awt.*;public class Panel1 { public static void main(String[] args) { Panel1 gui = new Panel1(); gui.go(); } publi转载 2015-07-29 08:19:10 · 382 阅读 · 0 评论 -
write to text file DEMO
package HeadFirstJava;import java.io.*;class WriteFile { public static void main(String[] args) { try { FileWriter writer = new FileWriter("Foo.txt"); writer.wr转载 2015-07-29 09:35:47 · 571 阅读 · 0 评论 -
use sleep() to gain thread predictability
package HeadFirstJava;class MyRunnable implements Runnable { public void run() { go(); } public void go() { try { Thread.sleep(2000); } catch(Interrup转载 2015-07-30 09:37:27 · 477 阅读 · 0 评论 -
thread unpredictability
package HeadFirstJava;class MyRunnable implements Runnable { public void run() { go(); } public void go() { doMore(); } public void doMore() { System.out.转载 2015-07-30 09:24:16 · 476 阅读 · 0 评论 -
start 2 threads
package HeadFirstJava;public class RunThreads implements Runnable { public static void main(String[] args) { RunThreads runner = new RunThreads(); // make a Runnable object Thre转载 2015-07-30 09:48:37 · 504 阅读 · 0 评论 -
synchronized keyword DEMO
package HeadFirstJava;class BankAccount { private int balance = 100; public int getBalance() { return balance; } public void withdraw(int amount) { balance = bal转载 2015-07-30 10:32:31 · 621 阅读 · 0 评论 -
without synchronized keyword
package HeadFirstJava;class BankAccount { private int balance = 100; public int getBalance() { return balance; } public void withdraw(int amount) { balance = bal转载 2015-07-30 10:33:51 · 610 阅读 · 0 评论 -
Simple Java GUI DEMO(quote from head first java 2e)
import javax.swing.*;import java.awt.*;import java.awt.event.*;@SuppressWarnings("serial")class MyDrawPanel extends JPanel { public void paintComponent(Graphics g) { g.fillRect(0, 0转载 2015-07-23 10:44:22 · 557 阅读 · 0 评论 -
2 event source & inner class DEMO(quote from Head First Java 2e)
import java.awt.BorderLayout;import java.awt.Color;import java.awt.Graphics;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.转载 2015-07-23 11:21:01 · 376 阅读 · 0 评论 -
String::split() DEMO
package HeadFirstJava;public class TestJava { public static void main(String[] args) { String toTest = "What is blue + yellow?/green"; String[] result = toTest.split("/");转载 2015-07-29 10:08:15 · 394 阅读 · 0 评论 -
read text file DEMO
package HeadFirstJava;import java.io.*;class ReadAFile { public static void main(String[] args) { try { File myFile = new File("MyText.txt"); FileReader fileRea转载 2015-07-29 10:01:08 · 429 阅读 · 0 评论 -
flow layout DEMO
package HeadFirstJava;import javax.swing.*;import java.awt.*;public class Panel1 { public static void main(String[] args) { Panel1 gui = new Panel1(); gui.go(); } publi转载 2015-07-29 08:09:08 · 554 阅读 · 0 评论 -
Java calendar DEMO
import java.util.Calendar;public class Test { public static void main(String[] args) { Calendar c = Calendar.getInstance(); System.out.println(c.getTime()); }}Mon Jul 27 1原创 2015-07-27 12:08:23 · 440 阅读 · 0 评论 -
OO in java DEMO
// quote from "Head First Java, 2e"public class GameLauncher { public static void main(String[] args) { GuessGame game = new GuessGame(); game.startGame(); }}public class G转载 2015-07-27 09:25:47 · 339 阅读 · 0 评论 -
Java DEMO
// quote from "Head First Java, 2e"// FileName: DogTestDrive.javaclass Dog { int size; String bred; String name; void bark() { System.out.println("Ruff! Ruff!"); }}转载 2015-07-27 09:00:53 · 405 阅读 · 0 评论 -
2 event sources & inner class
import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;@SuppressWarnings("serial")class MyDrawPanel extends JPanel { public void paint转载 2015-07-28 10:00:48 · 414 阅读 · 0 评论 -
Border Layout demo
package HeadFirstJava;import javax.swing.*;import java.awt.*;public class Button { public static void main(String[] args) { Button gui = new Button(); gui.go(); } publi转载 2015-07-28 11:58:15 · 805 阅读 · 0 评论 -
BorderLayout manager DEMO
package HeadFirstJava;import javax.swing.*;import java.awt.*;public class Button { public static void main(String[] args) { Button gui = new Button(); gui.go(); } publi转载 2015-07-28 11:40:23 · 397 阅读 · 0 评论 -
Java simple GUI DEMO
import javax.swing.*;public class SimpleGui { public static void main(String[] args) { JFrame frame = new JFrame(); JButton button = new JButton("click me"); fra转载 2015-07-28 08:50:15 · 582 阅读 · 0 评论 -
draw something in Java DEMO
import java.awt.*;import javax.swing.*;@SuppressWarnings("serial")class MyDrawPanel extends JPanel { public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; G转载 2015-07-28 09:27:59 · 609 阅读 · 0 评论 -
event source => listener
package HeadFirstJava;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class SimpleGui { JButton button; public转载 2015-07-28 11:20:08 · 710 阅读 · 0 评论 -
event handling in Java
import javax.swing.*;import java.awt.event.*;public class SimpleGui implements ActionListener { JButton button; public static void main(String[] args) { SimpleGui gui = new Si转载 2015-07-28 09:03:48 · 718 阅读 · 1 评论 -
button with a big font
package HeadFirstJava;import javax.swing.*;import java.awt.*;public class Button { public static void main(String[] args) { Button gui = new Button(); gui.go(); } publi转载 2015-07-28 11:48:29 · 476 阅读 · 0 评论 -
inner class DEMO(quote from Head First Java 2e)
import javax.swing.*;import java.awt.*;public class SimpleAnimation { int x = 70; int y = 70; public static void main(String[] args) { SimpleAnimation gui = new SimpleAnima转载 2015-07-23 11:54:21 · 442 阅读 · 0 评论