写了一个applet,想通过html页面显示出来,可是提示找不到类,请教大师们,给点指点
这个是applet代码package hello;import java.applet.Applet;
import java.awt.Color;
import java.awt.Panel;
import java.awt.geom.Rectangle2D;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JScrollPane;import org.jgraph.JGraph;
import org.jgraph.graph.ConnectionSet;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.DefaultPort;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphModel;public class ShowJgraph extends Applet { public void init(){
try{
java.awt.EventQueue.invokeAndWait(new Runnable(){
public void run(){
showGraph();
}
});
}catch(Exception e){
e.printStackTrace();
}
}
public void showGraph(){
String driverName="com.mysql.jdbc.Driver";
String userName="root";
String userPwd="root";
String dbName="funonto";
String tableName="tree";
String url="jdbc:mysql://localhost:3306/"+dbName+"?user="+userName+"&password="+userPwd;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection conn=DriverManager.getConnection(url);
System.out.println("数据库连接成功!");
java.sql.Statement statement=conn.createStatement();
String sql="SELECT nodeName FROM "+tableName;
java.sql.ResultSet rs=statement.executeQuery(sql);
ArrayList al=new ArrayList();
while(rs.next()){
//Iterator it=rs.iterator();
al.add(rs.getString(1));
//System.out.println(rs.getString(1));
//System.out.println(al);
}
Iterator it=al.iterator();
/*while(it.hasNext())
System.out.println(it.next());*/
GraphModel gmodel=new DefaultGraphModel();
JGraph graph=new JGraph(gmodel);
//graph.addSelectionCell(true);
Map attributes=new Hashtable();
DefaultGraphCell fun=new DefaultGraphCell("fridge");
Map funAttrib=new Hashtable();
attributes.put(fun, funAttrib);
Rectangle2D funBounds=new Rectangle2D.Double(20,20,60,20);
GraphConstants.setBounds(funAttrib,funBounds);
GraphConstants.setBorderColor(funAttrib, Color.black);
DefaultPort hp=new DefaultPort();
fun.add(hp);
DefaultGraphCell subfun;
int count=0;
while(it.hasNext()){
if(it.hasNext())
count++;
//System.out.println(count+","+it.next());
it.next();
subfun=new DefaultGraphCell(it.next());
Map subAttrib=new Hashtable();
attributes.put(subfun, subAttrib);
Rectangle2D subBounds=new Rectangle2D.Double(20+10*count,20+20*count,60,20);
GraphConstants.setBounds(subAttrib,subBounds);
GraphConstants.setBorder(subAttrib, BorderFactory.createRaisedBevelBorder());
DefaultPort wp=new DefaultPort();
subfun.add(wp);
DefaultEdge edge=new DefaultEdge();
Map edgeAttrib=new Hashtable();
attributes.put(edge, edgeAttrib);
//int arrow=GraphConstants.ARROW_CLASSIC;
int arrow=GraphConstants.ARROW_TECHNICAL;
GraphConstants.setLineEnd(edgeAttrib, arrow);
GraphConstants.setEndFill(edgeAttrib, true);
ConnectionSet cs=new ConnectionSet(edge,hp,wp);
Object[] cells=new Object[]{edge,fun,subfun};
gmodel.insert(cells, attributes, cs, null, null);
}
/*JFrame frame=new JFrame();
frame.getContentPane().add(new JScrollPane(graph));
frame.pack();
frame.setVisible(true);*/
Panel panel = new Panel();
panel.setSize(800000000, 60000000);
panel.add(new JScrollPane(graph));
this.add(panel);
//for()
/*System.out.print("功能ID ");
System.out.print(" | ");
System.out.print("功能名称 ");
System.out.print(" | ");
System.out.print("父功能 ");
System.out.println();
while(rs.next()){
System.out.print(rs.getString(1)+" ");
System.out.print(" | ");
System.out.print(rs.getString(3)+" ");
System.out.print(" | ");
System.out.print(rs.getString(2));
System.out.println();
}
System.out.println();*/
System.out.print("数据库操作成功!");
rs.close();
statement.close();
conn.close();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这个是html代码<html>
<head>
</head>
<body>
<applet codebase="."
archive="jgraph.jar,mysql-connector-java-5.0.8-bin.jar"
code="ShowJgraph.class"
name="ShowJgraph"
width="320"
height="240">
</applet>
</body>
</html>这两个文件都在同一目录下,还有用到的两个jar包,谢谢大师们指点
这个是applet代码package hello;import java.applet.Applet;
import java.awt.Color;
import java.awt.Panel;
import java.awt.geom.Rectangle2D;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JScrollPane;import org.jgraph.JGraph;
import org.jgraph.graph.ConnectionSet;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.DefaultPort;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphModel;public class ShowJgraph extends Applet { public void init(){
try{
java.awt.EventQueue.invokeAndWait(new Runnable(){
public void run(){
showGraph();
}
});
}catch(Exception e){
e.printStackTrace();
}
}
public void showGraph(){
String driverName="com.mysql.jdbc.Driver";
String userName="root";
String userPwd="root";
String dbName="funonto";
String tableName="tree";
String url="jdbc:mysql://localhost:3306/"+dbName+"?user="+userName+"&password="+userPwd;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection conn=DriverManager.getConnection(url);
System.out.println("数据库连接成功!");
java.sql.Statement statement=conn.createStatement();
String sql="SELECT nodeName FROM "+tableName;
java.sql.ResultSet rs=statement.executeQuery(sql);
ArrayList al=new ArrayList();
while(rs.next()){
//Iterator it=rs.iterator();
al.add(rs.getString(1));
//System.out.println(rs.getString(1));
//System.out.println(al);
}
Iterator it=al.iterator();
/*while(it.hasNext())
System.out.println(it.next());*/
GraphModel gmodel=new DefaultGraphModel();
JGraph graph=new JGraph(gmodel);
//graph.addSelectionCell(true);
Map attributes=new Hashtable();
DefaultGraphCell fun=new DefaultGraphCell("fridge");
Map funAttrib=new Hashtable();
attributes.put(fun, funAttrib);
Rectangle2D funBounds=new Rectangle2D.Double(20,20,60,20);
GraphConstants.setBounds(funAttrib,funBounds);
GraphConstants.setBorderColor(funAttrib, Color.black);
DefaultPort hp=new DefaultPort();
fun.add(hp);
DefaultGraphCell subfun;
int count=0;
while(it.hasNext()){
if(it.hasNext())
count++;
//System.out.println(count+","+it.next());
it.next();
subfun=new DefaultGraphCell(it.next());
Map subAttrib=new Hashtable();
attributes.put(subfun, subAttrib);
Rectangle2D subBounds=new Rectangle2D.Double(20+10*count,20+20*count,60,20);
GraphConstants.setBounds(subAttrib,subBounds);
GraphConstants.setBorder(subAttrib, BorderFactory.createRaisedBevelBorder());
DefaultPort wp=new DefaultPort();
subfun.add(wp);
DefaultEdge edge=new DefaultEdge();
Map edgeAttrib=new Hashtable();
attributes.put(edge, edgeAttrib);
//int arrow=GraphConstants.ARROW_CLASSIC;
int arrow=GraphConstants.ARROW_TECHNICAL;
GraphConstants.setLineEnd(edgeAttrib, arrow);
GraphConstants.setEndFill(edgeAttrib, true);
ConnectionSet cs=new ConnectionSet(edge,hp,wp);
Object[] cells=new Object[]{edge,fun,subfun};
gmodel.insert(cells, attributes, cs, null, null);
}
/*JFrame frame=new JFrame();
frame.getContentPane().add(new JScrollPane(graph));
frame.pack();
frame.setVisible(true);*/
Panel panel = new Panel();
panel.setSize(800000000, 60000000);
panel.add(new JScrollPane(graph));
this.add(panel);
//for()
/*System.out.print("功能ID ");
System.out.print(" | ");
System.out.print("功能名称 ");
System.out.print(" | ");
System.out.print("父功能 ");
System.out.println();
while(rs.next()){
System.out.print(rs.getString(1)+" ");
System.out.print(" | ");
System.out.print(rs.getString(3)+" ");
System.out.print(" | ");
System.out.print(rs.getString(2));
System.out.println();
}
System.out.println();*/
System.out.print("数据库操作成功!");
rs.close();
statement.close();
conn.close();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这个是html代码<html>
<head>
</head>
<body>
<applet codebase="."
archive="jgraph.jar,mysql-connector-java-5.0.8-bin.jar"
code="ShowJgraph.class"
name="ShowJgraph"
width="320"
height="240">
</applet>
</body>
</html>这两个文件都在同一目录下,还有用到的两个jar包,谢谢大师们指点
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货