Java: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 22: | Line 22: | ||
= Swing = | = Swing = | ||
* http://zetcode.com/tutorials/javaswingtutorial/ | * http://zetcode.com/tutorials/javaswingtutorial/ | ||
For example, use 'nano SimpleExample.java' to create a new file | |||
<pre> | |||
package com.zetcode; | |||
import javax.swing.JFrame; | |||
import javax.swing.SwingUtilities; | |||
public class SimpleExample extends JFrame { | |||
public SimpleExample() { | |||
setTitle("Simple example"); | |||
setSize(300, 200); | |||
setLocationRelativeTo(null); | |||
setDefaultCloseOperation(EXIT_ON_CLOSE); | |||
} | |||
public static void main(String[] args) { | |||
SwingUtilities.invokeLater(new Runnable() { | |||
@Override | |||
public void run() { | |||
SimpleExample ex = new SimpleExample(); | |||
ex.setVisible(true); | |||
} | |||
}); | |||
} | |||
} | |||
</pre> | |||
Then | |||
<pre> | |||
javac SimpleExample.java # generate SimpleExamples.class and SimpleExample$1.class | |||
</pre> | |||
Revision as of 10:27, 3 March 2014
Install openjdk
See http://openjdk.java.net/install/. On Ubuntu, I can use
sudo apt-get install openjdk-7-jdk
Some projects written in Java
- FastQC The code uses Java 2D graphics APIs in awt like BasicStroke, Color, Dimension, Graphics, Graphics2D, RenderingHints and javax.swing.JPanel. It also uses java.util.Vector.
Tutorial
Compile a simple Java program
javac Example.java # generate Example.class; bytecode version of the program java Example # run bytecode in Java Virtual Machine
Swing
For example, use 'nano SimpleExample.java' to create a new file
package com.zetcode;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class SimpleExample extends JFrame {
public SimpleExample() {
setTitle("Simple example");
setSize(300, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
SimpleExample ex = new SimpleExample();
ex.setVisible(true);
}
});
}
}
Then
javac SimpleExample.java # generate SimpleExamples.class and SimpleExample$1.class