Estou agora a tentar usar o JApplet, mas estou a ter algumas dificuldades.:oops:
Segundo o q me foi dito para o JApplet funcionar, a unica diferenca era introduzir o codigo no metodo init() e foi o q fiz. Ate aki tudo bem, ele contruiu a componente grafica correctamente e ate funcionam os listeners, mas qd tento executar uma tarefa ele simplesmente envia este erro:
não creio q isto seja um problema de codigo, pois tenho o mm codigo a funcionar correctamente no JFrame... :roll:
Aki fika a classe q implementa o JApplet e q envia aquela excepçao:
/*
* applet.java
*
* Created on July 22, 2004, 10:10 AM
*/
package win;
import app.*;
import javax.swing.table.*;
/**
*
* @author botelhodaniel
*/
public class applet extends javax.swing.JApplet {
private Items items;
private TableSorter sorter,tempSorter;
int[] columnSizes;
int rowSelected;
/** Initializes the applet applet */
public void init() {
columnSizes = new int[] {200,290,100,50};
initComponents();
}
private void addTableSorter() throws Exception{
items = new ReadHublist2(""+jComboBox1.getSelectedItem()).getItems();
sorter = new TableSorter(new PublicHubListTableModel(items));
jTable1 = new javax.swing.JTable(sorter);
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTable1MouseClicked(evt);
}
});
sorter.setTableHeader(jTable1.getTableHeader());
arranjarCol();
setStatusBar(jTable1);
jScrollPane1.setViewportView(jTable1);
jTextField1.setEnabled(true);
}
public void applyFilterToTable(){
Items filteredItems=new Items();
for(int i=0;i<sorter.getRowCount();i++){
if(
util.containsString(sorter.getTableModel().getValueAt(i, Items.address).toString(),jTextField1.getText())
|| util.containsString(sorter.getTableModel().getValueAt(i, Items.desc).toString(),jTextField1.getText())
|| util.containsString(sorter.getTableModel().getValueAt(i, Items.name).toString(),jTextField1.getText()))
filteredItems.addItem(items.getItem(i));
}
//filteredItems.printItems();
tempSorter = new TableSorter(new PublicHubListTableModel(filteredItems));
jTable1.setModel(tempSorter);
tempSorter.setTableHeader(jTable1.getTableHeader());
setStatusBar(jTable1);
jScrollPane1.setViewportView(jTable1);
}
private void setStatusBar(javax.swing.JTable tabela){
int nHubs = tabela.getRowCount();
int nUsers=0;
for(int i=0; i<nHubs;i++)
nUsers=nUsers+(new Integer((tabela.getValueAt(i,3)).toString())).intValue();
jTextArea1.setText("H: "+nHubs);
jTextArea2.setText("U: "+nUsers);
}
private void arranjarCol(){
TableColumn column = null;
for (int i = 0; i < jTable1.getColumnCount(); i++)
{
column = jTable1.getColumnModel().getColumn(i);
column.setPreferredWidth(columnSizes[i]);
}
}
private void arranjaJPopupMenu(){
if(jTable1.getValueAt(rowSelected,Items.name).equals(" "))
nameMenuItem.setEnabled(false);
else
nameMenuItem.setEnabled(true);
if(jTable1.getValueAt(rowSelected,Items.address).equals(" "))
addressMenuItem.setEnabled(false);
else
addressMenuItem.setEnabled(true);
if(jTable1.getValueAt(rowSelected,Items.desc).equals(" "))
descMenuItem.setEnabled(false);
else
descMenuItem.setEnabled(true);
if(jTable1.getValueAt(rowSelected,Items.users).equals(" "))
usersMenuItem.setEnabled(false);
else
usersMenuItem.setEnabled(true);
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
jPopupMenu1 = new javax.swing.JPopupMenu();
openMenuItem = new javax.swing.JMenuItem();
jMenu1 = new javax.swing.JMenu();
nameMenuItem = new javax.swing.JMenuItem();
addressMenuItem = new javax.swing.JMenuItem();
descMenuItem = new javax.swing.JMenuItem();
usersMenuItem = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JSeparator();
allMenuItem = new javax.swing.JMenuItem();
jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jComboBox1 = new javax.swing.JComboBox();
jPanel2 = new javax.swing.JPanel();
jPanel4 = new javax.swing.JPanel();
jTextArea1 = new javax.swing.JTextArea();
jTextArea2 = new javax.swing.JTextArea();
jScrollPane1 = new javax.swing.JScrollPane();
openMenuItem.setText(StringDef.OPEN_HUB);
openMenuItem.setToolTipText(StringDef.TOOLTIP_OH);
openMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
openMenuItemActionPerformed(evt);
}
});
jPopupMenu1.add(openMenuItem);
jMenu1.setText(StringDef.COPY);
nameMenuItem.setText(StringDef.HUB_NAME.toLowerCase());
nameMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nameMenuItemActionPerformed(evt);
}
});
jMenu1.add(nameMenuItem);
addressMenuItem.setText(StringDef.HUB_ADD.toLowerCase());
addressMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addressMenuItemActionPerformed(evt);
}
});
jMenu1.add(addressMenuItem);
descMenuItem.setText(StringDef.HUB_DESC.toLowerCase());
descMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
descMenuItemActionPerformed(evt);
}
});
jMenu1.add(descMenuItem);
usersMenuItem.setText(StringDef.HUB_USERS.toLowerCase());
usersMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
usersMenuItemActionPerformed(evt);
}
});
jMenu1.add(usersMenuItem);
jMenu1.add(jSeparator1);
allMenuItem.setText(StringDef.ALL.toLowerCase());
allMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
allMenuItemActionPerformed(evt);
}
});
jMenu1.add(allMenuItem);
jPopupMenu1.add(jMenu1);
jPanel1.setLayout(new java.awt.FlowLayout());
jTextField1.setColumns(20);
jTextField1.setEnabled(false);
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
jTextField1KeyReleased(evt);
}
});
jPanel1.add(jTextField1);
jComboBox1.setEditable(true);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "http://p2p-pt.com/listadinamica/PublicHubList.config", "http://www.p2p-pt.com/PublicHubList.config", "http://www.p2p-pt.com/PublicHubListTodosMesmo.config", "http://www.neo-modus.com/PublicHubList.config", "http://www.rohubstats.go.ro/PublicHubList.config", "http://www.indx.f2s.com/hublist.config", "http://www.galy.szm.sk/CZHubListON.config", "http://nevienc.sytes.net/dcpp.config", "http://www.zpoc.com/rooms.config", "http://www.dc.nzgames.co.nz/publichublist.config", "http://ccorreia.no.sapo.pt/pthubs.config" }));
jComboBox1.setPreferredSize(new java.awt.Dimension(240, 24));
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt);
}
});
jPanel1.add(jComboBox1);
getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
jPanel2.setLayout(new java.awt.BorderLayout());
jPanel4.setLayout(new java.awt.FlowLayout());
jTextArea1.setBackground(new java.awt.Color(204, 204, 204));
jTextArea1.setColumns(5);
jTextArea1.setEditable(false);
jPanel4.add(jTextArea1);
jTextArea2.setBackground(new java.awt.Color(204, 204, 204));
jTextArea2.setColumns(5);
jTextArea2.setEditable(false);
jPanel4.add(jTextArea2);
jPanel2.add(jPanel4, java.awt.BorderLayout.CENTER);
getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
}
private void allMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
StringBuffer string = new StringBuffer();
string.append(jTable1.getValueAt(rowSelected,Items.name)+" ");
string.append(jTable1.getValueAt(rowSelected,Items.address)+" ");
string.append(jTable1.getValueAt(rowSelected,Items.desc)+" ");
string.append(jTable1.getValueAt(rowSelected,Items.users)+"");
java.awt.datatransfer.StringSelection selection = new java.awt.datatransfer.StringSelection(string.toString());
java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null);
}
private void usersMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
java.awt.datatransfer.StringSelection selection = new java.awt.datatransfer.StringSelection(jTable1.getValueAt(rowSelected,Items.users)+"");
java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null);
}
private void descMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
java.awt.datatransfer.StringSelection selection = new java.awt.datatransfer.StringSelection((String)jTable1.getValueAt(rowSelected,Items.desc));
java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null);
}
private void addressMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
java.awt.datatransfer.StringSelection selection = new java.awt.datatransfer.StringSelection((String)jTable1.getValueAt(rowSelected,Items.address));
java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null);
}
private void nameMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
java.awt.datatransfer.StringSelection selection = new java.awt.datatransfer.StringSelection((String)jTable1.getValueAt(rowSelected,Items.name));
java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null);
}
private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String cmd= new String();
try{
if(OS.getOS().startsWith("Windows"))
cmd= "rundll32 url.dll,FileProtocolHandler dchub://"+jTable1.getValueAt(rowSelected,Items.address)+"";
else
cmd = "dcgui-qt";
Runtime.getRuntime().exec(cmd);
} catch (Exception e){System.err.println(e);}
}
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
addTableSorter();
} catch(Exception e ){
javax.swing.JOptionPane.showMessageDialog(null, ""+e, "alert", javax.swing.JOptionPane.ERROR_MESSAGE);
}
}
private void jTextField1KeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
applyFilterToTable();
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
applyFilterToTable();
}
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if(javax.swing.SwingUtilities.isRightMouseButton(evt)){
int ajusteY=jScrollPane1.getVerticalScrollBar().getValue();
int ajusteX=jScrollPane1.getHorizontalScrollBar().getValue();
rowSelected = jTable1.rowAtPoint(new java.awt.Point(evt.getX(),evt.getY()));
arranjaJPopupMenu();
jPopupMenu1.show(jScrollPane1, evt.getX()-ajusteX, evt.getY()-ajusteY);
}
}
private javax.swing.JTable jTable1;
// Variables declaration - do not modify
private javax.swing.JMenuItem addressMenuItem;
private javax.swing.JMenuItem allMenuItem;
private javax.swing.JMenuItem descMenuItem;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JMenu jMenu1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel4;
private javax.swing.JPopupMenu jPopupMenu1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
private javax.swing.JTextField jTextField1;
private javax.swing.JMenuItem nameMenuItem;
private javax.swing.JMenuItem openMenuItem;
private javax.swing.JMenuItem usersMenuItem;
// End of variables declaration
}
Pergunta
Guest [PT]Devilishly
Boas!
Estou agora a tentar usar o JApplet, mas estou a ter algumas dificuldades.:oops:
Segundo o q me foi dito para o JApplet funcionar, a unica diferenca era introduzir o codigo no metodo init() e foi o q fiz. Ate aki tudo bem, ele contruiu a componente grafica correctamente e ate funcionam os listeners, mas qd tento executar uma tarefa ele simplesmente envia este erro:
não creio q isto seja um problema de codigo, pois tenho o mm codigo a funcionar correctamente no JFrame... :roll:
Aki fika a classe q implementa o JApplet e q envia aquela excepçao:
O codigo fonte encontra-se neste ficheiro: PublicHubList-0.03.tar.gz
O ficheiro MainFrame.java e' a class main e o applet.java e' onde se encontra a class q apresentei acima...
Obrigado pela ajuda
Fikem bem,
[PT]Devilishly
Link para o comentário
Compartilhar em outros sites
4 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.