Hi,
habe noch ein Paar Probleme mit JApplets...
Ich würde gerne ein kleines Programm in ein Applet verwandeln um es innerhalb meines DokuWiki in einer HTML Datei laufen zu lassen.
Aber ich kriege es nicht ganz hin das Programm so umzuschreiben das daraus ein Applet wird....
könnte mir da wer helfen, bitte?
Zum Verständnis des Programms: 3 Dateien... (eigentlich 4 aber die Dritte stellt nur die OracleVerbindung her)
wie muss ich das jetzt umschreiben das daraus ein Applet wird? :rtfm:
habe noch ein Paar Probleme mit JApplets...
Ich würde gerne ein kleines Programm in ein Applet verwandeln um es innerhalb meines DokuWiki in einer HTML Datei laufen zu lassen.
Aber ich kriege es nicht ganz hin das Programm so umzuschreiben das daraus ein Applet wird....
könnte mir da wer helfen, bitte?
Zum Verständnis des Programms: 3 Dateien... (eigentlich 4 aber die Dritte stellt nur die OracleVerbindung her)
- Oracle SQL Abfrage die in Tabelle geschrieben wird
- Tablemodell
- Simples GUI mit nur einem Knopf (mit NetBeans)
Java:
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.applet.Applet;
import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
public class AP{
public static void main(String[] argv) throws Exception {
JTable table = new JTable(myModel());
JFrame f = new JFrame();
f.setSize(1400, 600);
f.add(new JScrollPane(table));
table.setBackground(Color.LIGHT_GRAY);
WindowListener wClose = new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
};
f.setVisible(true);
}
public static FillTable myModel() throws Exception{
/*try {
Class.forName ("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection con = DriverManager.getConnection
("jdbc:oracle:thin:@Host:port:sid", "user", "pass");
*/
Connection con = _DB_Connection.getConnection();
Statement st = con.createStatement();
String tableName = "E_Tabelle";
ResultSet rs = st.executeQuery("SELECT * FROM " + tableName);
FillTable model = new FillTable(rs);
return model;
}
}
Java:
import java.sql.*;
import java.util.*;
import javax.swing.table.*;
public class FillTable extends AbstractTableModel{
/**
*
*/
private static final long serialVersionUID = -912060609250881296L;
private ResultSet rs;
private int rowCount;
private int columnCount;
private ArrayList data=new ArrayList();
public FillTable(ResultSet _rs) throws Exception
{
setRS(_rs);
}
public void setRS(ResultSet _rs)
throws Exception
{
this.rs=_rs;
ResultSetMetaData metaData=_rs.getMetaData();
rowCount=0;
columnCount=metaData.getColumnCount();
while(_rs.next()){
Object[] row=new Object[columnCount];
for(int j=0;j<columnCount;j++){
row[j]=_rs.getObject(j+1);
}
data.add(row);
rowCount++;
}
}
public int getColumnCount(){
return columnCount;
}
public int getRowCount(){
return rowCount;
}
public Object getValueAt(int rowIndex, int columnIndex){
Object[] row=(Object[]) data.get(rowIndex);
return row[columnIndex];
}
public String getColumnName(int columnIndex){
try{
ResultSetMetaData metaData=rs.getMetaData();
return metaData.getColumnName(columnIndex+1);
}catch(Exception e){
e.printStackTrace();
return null;
}
}
}
Java:
import java.util.logging.Level;
import java.util.logging.Logger;
public class NewJFrame extends javax.swing.JFrame {
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("TESTTESTETEATE");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(158, 158, 158)
.addComponent(jButton1)
.addContainerGap(125, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(67, 67, 67)
.addComponent(jButton1)
.addContainerGap(210, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
String[] argv = null;
AP.main(argv);
} catch (Exception ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see [url=http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html]How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)[/url]
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
// End of variables declaration
}
wie muss ich das jetzt umschreiben das daraus ein Applet wird? :rtfm:
Zuletzt bearbeitet: