当前位置: 技术问答>unix/linux知识
iis7站长之家
applet和swing的问题(急)
来源: 互联网 发布时间:2017-03-21
本文导语: 想在applet中嵌入swing,以及它的事件响应实现,以前没接触过applet和swing,时间较急,请问有没有这方面的文档可以参考,希望高人指点. | 如果用AWT就不用plugin了,当然界面也变简陋了一些。 jbuilder...
想在applet中嵌入swing,以及它的事件响应实现,以前没接触过applet和swing,时间较急,请问有没有这方面的文档可以参考,希望高人指点.
|
如果用AWT就不用plugin了,当然界面也变简陋了一些。
jbuilder下可以以可视化的方式设计界面,挺方便的。你就看它自带的帮助好了。
我的程序,原本是用swing的,后来又改成了用awt,两个版本都给你好了。不过它要后台数据库支持,可能运行不起来。(不过图形界面应该可以出来)
你看看吧,我发过去了希望对你有用。
jbuilder下可以以可视化的方式设计界面,挺方便的。你就看它自带的帮助好了。
我的程序,原本是用swing的,后来又改成了用awt,两个版本都给你好了。不过它要后台数据库支持,可能运行不起来。(不过图形界面应该可以出来)
你看看吧,我发过去了希望对你有用。
|
应该是可以的,
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.f1j.swing.*;
import java.lang.*;
import java.awt.Color;
import com.microsoft.jdbc.base.*;
import java.io.*;
import java.sql.*;
public class FirstTestFormula extends JFrame implements java.awt.event.ActionListener
{
private Connection con;
private PreparedStatement pstmt;
private Statement stmt;
private ResultSet rs;
com.f1j.ss.CellFormat originalCellFormat;//网格的信息,也就是单元格的信息
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JButton btnSimple = new JButton();
JBook jBook1 = new JBook();
//Construct the frame
public void init()
{
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.out.println("加载数据库驱动程序失败!"+e.getMessage());
}
}
public boolean connect(String url,String database,String user,String pass)
{
try{
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://"+url+":1433;DatabaseName="+database,user,pass);
return true;
}
catch(Exception e)
{
System.out.println("连接数据库失败!"+e.getMessage());
System.out.println("url="+url+"database="+database+"user="+user+"password="+pass);
return false;
}
}
public FirstTestFormula()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
static public void main(String args[])
{
System.out.println("begin running……");
FirstTestFormula frame = new FirstTestFormula();
frame.validate();
frame.setVisible(true);
}
//Component initialization
private void jbInit() throws Exception
{
this.init();
this.connect("server2000","nrPS_DB","sa","njbool");
this.getContentPane().setLayout(borderLayout1);
this.setSize(new Dimension(800, 600));
this.setTitle("Format Demo");
btnSimple.setText("Simple");
btnSimple.setBounds(new Rectangle(6, 3, 111, 35));
btnSimple.addActionListener(this);
/*****************/
jPanel1.setLayout(null);
jBook1.setBounds(new Rectangle(4, 173, 507, 293));
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jBook1, null);
jPanel1.add(btnSimple, null);
}
//Overridden so we can exit on System Close
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if(e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
}
public void actionPerformed(java.awt.event.ActionEvent e)
{
Object buttonObj = e.getSource();
if(buttonObj==btnSimple)
{
btnSimple_actionPerformed();
}
}
public InputStream readStream(String dbname,int pic_id)
{
int gifLength=0;
InputStream input;
try{
pstmt=con.prepareStatement("select datalength(Content) from "+dbname+" where T_id= ?");
pstmt.setInt(1,pic_id);
rs=pstmt.executeQuery();
rs.next();
gifLength=rs.getInt(1);
System.out.println("gifLength="+gifLength);
rs.close();
pstmt.close();
pstmt=con.prepareStatement("select Content from "+dbname+" where T_id= ?");
pstmt.setInt(1,pic_id);
rs = pstmt.executeQuery();
rs.next();
input=rs.getBinaryStream(1);
return input;
}
catch(Exception ex)
{
System.out.println("读取数据库底图失败:"+ex.getMessage());
System.out.println("dbname="+dbname+" "+"pic_id="+pic_id);
return null;
}
}
public void btnSimple_actionPerformed()
{
InputStream input;
System.out.println("run event……");
try
{
jBook1.setSelection(1,1,7,5);
}
catch (com.f1j.util.F1Exception e)
{
System.out.println(e.getMessage());
}
// String dirName = System.getProperty("user.dir");
// String fileName = "book1.vts";
try {
input=this.readStream("STEMPLETS",1);
//jBook1.read(dirName + "\" + fileName);
jBook1.read(input);
jBook1.setShowGridLines(false);
jBook1.setSelection(1,1,7,5);
jBook1.editClear(jBook1.eClearFormats);//清除
String savedSelection = jBook1.getSelection();
originalCellFormat = jBook1.getCellFormat();//返回一个CellFormat
originalCellFormat.setHorizontalAlignment(this.originalCellFormat.eHorizontalAlignmentRight);
originalCellFormat.setTopBorder(com.f1j.ss.CellFormat.eBorderThin);//实线
originalCellFormat.setBottomBorder(com.f1j.ss.CellFormat.eBorderDashed);//虚线
originalCellFormat.setLeftBorder(com.f1j.ss.CellFormat.eBorderMediumDashDotDot);
jBook1.setCellFormat(this.originalCellFormat);
}
catch (com.f1j.util.F1Exception e)
{
System.out.println(e.getMessage());
}
catch (java.io.IOException io)
{
System.out.println(io.getMessage());
}
}
}
我在做一个applet,放到iis服务上面,只是在applet引进两个com包,和swing没关系的,我的 swing可以用的,在客户端是装了jdk1.3的,
代码通过!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.f1j.swing.*;
import java.lang.*;
import java.awt.Color;
import com.microsoft.jdbc.base.*;
import java.io.*;
import java.sql.*;
public class FirstTestFormula extends JFrame implements java.awt.event.ActionListener
{
private Connection con;
private PreparedStatement pstmt;
private Statement stmt;
private ResultSet rs;
com.f1j.ss.CellFormat originalCellFormat;//网格的信息,也就是单元格的信息
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JButton btnSimple = new JButton();
JBook jBook1 = new JBook();
//Construct the frame
public void init()
{
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.out.println("加载数据库驱动程序失败!"+e.getMessage());
}
}
public boolean connect(String url,String database,String user,String pass)
{
try{
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://"+url+":1433;DatabaseName="+database,user,pass);
return true;
}
catch(Exception e)
{
System.out.println("连接数据库失败!"+e.getMessage());
System.out.println("url="+url+"database="+database+"user="+user+"password="+pass);
return false;
}
}
public FirstTestFormula()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
static public void main(String args[])
{
System.out.println("begin running……");
FirstTestFormula frame = new FirstTestFormula();
frame.validate();
frame.setVisible(true);
}
//Component initialization
private void jbInit() throws Exception
{
this.init();
this.connect("server2000","nrPS_DB","sa","njbool");
this.getContentPane().setLayout(borderLayout1);
this.setSize(new Dimension(800, 600));
this.setTitle("Format Demo");
btnSimple.setText("Simple");
btnSimple.setBounds(new Rectangle(6, 3, 111, 35));
btnSimple.addActionListener(this);
/*****************/
jPanel1.setLayout(null);
jBook1.setBounds(new Rectangle(4, 173, 507, 293));
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jBook1, null);
jPanel1.add(btnSimple, null);
}
//Overridden so we can exit on System Close
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if(e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
}
public void actionPerformed(java.awt.event.ActionEvent e)
{
Object buttonObj = e.getSource();
if(buttonObj==btnSimple)
{
btnSimple_actionPerformed();
}
}
public InputStream readStream(String dbname,int pic_id)
{
int gifLength=0;
InputStream input;
try{
pstmt=con.prepareStatement("select datalength(Content) from "+dbname+" where T_id= ?");
pstmt.setInt(1,pic_id);
rs=pstmt.executeQuery();
rs.next();
gifLength=rs.getInt(1);
System.out.println("gifLength="+gifLength);
rs.close();
pstmt.close();
pstmt=con.prepareStatement("select Content from "+dbname+" where T_id= ?");
pstmt.setInt(1,pic_id);
rs = pstmt.executeQuery();
rs.next();
input=rs.getBinaryStream(1);
return input;
}
catch(Exception ex)
{
System.out.println("读取数据库底图失败:"+ex.getMessage());
System.out.println("dbname="+dbname+" "+"pic_id="+pic_id);
return null;
}
}
public void btnSimple_actionPerformed()
{
InputStream input;
System.out.println("run event……");
try
{
jBook1.setSelection(1,1,7,5);
}
catch (com.f1j.util.F1Exception e)
{
System.out.println(e.getMessage());
}
// String dirName = System.getProperty("user.dir");
// String fileName = "book1.vts";
try {
input=this.readStream("STEMPLETS",1);
//jBook1.read(dirName + "\" + fileName);
jBook1.read(input);
jBook1.setShowGridLines(false);
jBook1.setSelection(1,1,7,5);
jBook1.editClear(jBook1.eClearFormats);//清除
String savedSelection = jBook1.getSelection();
originalCellFormat = jBook1.getCellFormat();//返回一个CellFormat
originalCellFormat.setHorizontalAlignment(this.originalCellFormat.eHorizontalAlignmentRight);
originalCellFormat.setTopBorder(com.f1j.ss.CellFormat.eBorderThin);//实线
originalCellFormat.setBottomBorder(com.f1j.ss.CellFormat.eBorderDashed);//虚线
originalCellFormat.setLeftBorder(com.f1j.ss.CellFormat.eBorderMediumDashDotDot);
jBook1.setCellFormat(this.originalCellFormat);
}
catch (com.f1j.util.F1Exception e)
{
System.out.println(e.getMessage());
}
catch (java.io.IOException io)
{
System.out.println(io.getMessage());
}
}
}
我在做一个applet,放到iis服务上面,只是在applet引进两个com包,和swing没关系的,我的 swing可以用的,在客户端是装了jdk1.3的,
代码通过!