java6 :
http://sdlc-esd.sun.com/ESD6/JSCDL/jdk/6u17-b04/jre-6u17-windows-i586-s.exe?AuthParam=1261379605_df3940062f8a88689627391e6e51f6bb&GroupName=JSC&FilePath=/ESD6/JSCDL/jdk/6u17-b04/jre-6u17-windows-i586-s.exe&File=jre-6u17-windows-i586-s.exe&BHost=javadl.sun.com
如果下不了,进[
http://www.java.com 在线安装。
java6 中文文档:
http://download.java.net/jdk/jdk-api-localizations/jdk-api-zh-cn/publish/1.6.0/chm/JDK_API_1_6_zh_CN.CHM
本人在eclipse 下测试
如果以前的旧的JDK ,要选择eclipse 的 window --> Preferences --> Java --> Compiler 下选java版本,还有下面的 configure 配 新的JDK路径,如果要用 Tomcat (以个人为例)等还要在 window --> Preferences --> MyElipse --> Application Server --> Tomcat --> JDK 选JAVA路径
脚本:
package com.c.elmer.java7.test;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class JavaScriptEngineTest {
public static void main(String[] args) {
try {
JavaScriptEngineTest test = new JavaScriptEngineTest();
test.sayHello("hermit");
} catch (Exception se) {
se.printStackTrace();
}
}
public void sayHello(String name) {
ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine jsEngine = sem.getEngineByName("js");
try {
jsEngine.eval("print('hello " + name + "')");
// jsEngine.eval("String s = \"aaaa\";");
// jsEngine.eval("println(s);");
} catch (ScriptException e) {
e.printStackTrace();
}
}
}
打开任何一个文件:
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.UIManager;
public class TestDesktopEditFile {
private JFrame frame;
/**
* Launch the application
*
* @param args
*/
public static void main(String args[]) {
try {
TestDesktopEditFile window = new TestDesktopEditFile();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the application
*/
public TestDesktopEditFile() {
initialize();
}
/**
* Initialize the contents of the frame
*/
private void initialize() {
try {
UIManager
.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception ex) {
ex.printStackTrace();
}
frame = new JFrame();
frame.getContentPane().setLayout(null);
frame.setBounds(100, 100, 225, 86);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton openButton = new JButton();
openButton.setBounds(53, 10, 106, 31);
openButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
JFileChooser jfc = new JFileChooser();
jfc.showOpenDialog(frame);
File file = jfc.getSelectedFile();
if (file != null) {
try {
desktop.edit(file);// 就这一行的区别
} catch (IOException e2) {
e2.printStackTrace();
}
}
} else {
System.out.println("不支持desktop");
}
}
});
openButton.setText("edit");// 哦哦哦,还有这一行也不一样,呵呵
frame.getContentPane().add(openButton);
}
}
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
public class TestDesktopOpenFile {
private JFrame frame;
/**
* Launch the application
*
* @param args
*/
public static void main(String args[]) {
try {
TestDesktopOpenFile window = new TestDesktopOpenFile();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the application
*/
public TestDesktopOpenFile() {
initialize();
}
/**
* Initialize the contents of the frame
*/
private void initialize() {
frame = new JFrame();
frame.getContentPane().setLayout(null);
frame.setBounds(100, 100, 225, 86);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton openButton = new JButton();
openButton.setBounds(53, 10, 106, 31);
openButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
JFileChooser jfc = new JFileChooser();
jfc.showOpenDialog(frame);
File file = jfc.getSelectedFile();
if (file != null) {
try {
desktop.open(file);
} catch (IOException e2) {
e2.printStackTrace();
}
}
} else {
System.out.println("不支持desktop");
}
}
});
openButton.setText("open");
frame.getContentPane().add(openButton);
}
}
java6 自身的webservice:
server:
package com.c.elmer.webserver.server;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
@WebService(targetNamespace = "http://jdk.study.hermit.org/client")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class Hello {
@WebMethod
public String sayHello(String name) {
return "hello:" + name;
}
}
package com.c.elmer.webserver.server;
import javax.xml.ws.Endpoint;
public class StartService {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8085/HelloService", new Hello());
}
}
client (client 可以写在另一个项目里,webservice 的优点):
package com.c.elmer.webserver.client;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
/**
* This class was generated by the JAXWS SI.
* JAX-WS RI 2.0_02-b08-fcs
* Generated source version: 2.0
*
*/
@WebService(name = "Hello", targetNamespace = "http://jdk.study.hermit.org/client")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface Hello {
/**
*
* @param arg0
* @return
* returns java.lang.String
*/
@WebMethod
@WebResult(partName = "return")
public String sayHello(
@WebParam(name = "arg0", partName = "arg0")
String arg0);
}
package com.c.elmer.webserver.client;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
/**
* This class was generated by the JAXWS SI.
* JAX-WS RI 2.0_02-b08-fcs
* Generated source version: 2.0
*
*/
@WebServiceClient(name = "HelloService", targetNamespace = "http://jdk.study.hermit.org/client", wsdlLocation = "http://localhost:8080/HelloService?wsdl")
public class HelloService
extends Service
{
private final static URL HELLOSERVICE_WSDL_LOCATION;
static {
URL url = null;
try {
url = new URL("http://localhost:8085/HelloService?wsdl");
} catch (MalformedURLException e) {
e.printStackTrace();
}
HELLOSERVICE_WSDL_LOCATION = url;
}
public HelloService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public HelloService() {
super(HELLOSERVICE_WSDL_LOCATION, new QName("http://jdk.study.hermit.org/client", "HelloService"));
}
/**
*
* @return
* returns Hello
*/
@WebEndpoint(name = "HelloPort")
public Hello getHelloPort() {
return (Hello)super.getPort(new QName("http://jdk.study.hermit.org/client", "HelloPort"), Hello.class);
}
}
package com.c.elmer.webserver.client;
public class TestClient {
public static void main(String[] args) {
HelloService service = new HelloService();
Hello _hello = service.getHelloPort();
System.out.println(_hello.sayHello("hermit"));
}
}
透明窗体:
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Window;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.JRadioButton;
import javax.swing.SwingUtilities;
public class TranslucentWindow extends JFrame {
public TranslucentWindow() {
super("透明窗体");
this.setLayout(new FlowLayout());
this.add(new JButton("按钮"));
this.add(new JCheckBox("复选按钮"));
this.add(new JRadioButton("单选按钮"));
this.add(new JProgressBar(20, 100));
this.setSize(new Dimension(400, 300));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Window w = new TranslucentWindow();
w.setVisible(true);
com.sun.awt.AWTUtilities.setWindowOpacity(w, 0.6f);
}
});
}
}
不规则窗体:
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Window;
import java.awt.geom.Ellipse2D;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.JRadioButton;
import javax.swing.SwingUtilities;
public class ShapedWindow extends JFrame {
public ShapedWindow() {
super("不规则窗体");
this.setLayout(new FlowLayout());
this.add(new JButton("按钮"));
this.add(new JCheckBox("复选按钮"));
this.add(new JRadioButton("单选按钮"));
this.add(new JProgressBar(0, 100));
this.setSize(new Dimension(400, 400));
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Window w = new ShapedWindow();
w.setVisible(true);
com.sun.awt.AWTUtilities.setWindowShape(w, new Ellipse2D.Double(
0, 0, w.getWidth(), w.getHeight()));
com.sun.awt.AWTUtilities.setWindowOpacity(w, 0.93f);
}
});
}
}