[Ajuda] criar frame para ler manual html

0 respostas
D

Ajuda para criar um frame para ler manual após clicar em um botão.

É bem simples, só que não consigo criar o frame e deixar o arquivo
html para leitura.
O frame é criado e nada mais acontece.

S]egue o código:

//Autor: Francis Rodrigues
//Para contato acesse: www.koderzone.com

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.JTabbedPane;
import javax.swing.Icon;
import javax.swing.ImageIcon;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

//imports para link funcionar:
import java.awt.Desktop;
import java.awt.Color;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

//pacotes forms:
import com.jgoodies.forms.factories.Borders;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;


public class manual {
  public JButton bSite;
  public JButton bHelp;
     
  public static void main(String[] args) {
     try {
       UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel");
    } catch (Exception e) {
    // Likely PlasticXP is not in the class path; ignore.
   }
   JFrame frame = new JFrame();
   frame.setTitle("Novo Cálculo salário");
   frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
   JComponent panel = new manual().buildPanel();
   frame.getContentPane().add(panel);
    //frame.setSize(600,400);
   frame.setResizable(false);
   frame.setLocation(200,80);
   frame.pack();
   frame.setVisible(true);
    }
       
/** criando painel principal: */
 public JComponent buildPanel() {
        JTabbedPane tabbedPane = new JTabbedPane();
        tabbedPane.putClientProperty("jgoodies.noContentBorder", Boolean.TRUE);
        tabbedPane.add("Manual",      buildInfo(true));
        return tabbedPane;
    }
     
 public void info() {
//botão html para aba de informações do criador do aplicativo:
  bSite = 
 new JButton("<html><body><font size=2>Acesse:<p><a href=\"http://www.guj.com.br\">www.guj.com.br</a></font></body></html>");    
  ActionListener listSite = new meuSite();
  bSite.addActionListener(listSite);

//botão help:
  Icon HelpIcon = new ImageIcon("img/help.gif");              
  bHelp = new JButton(HelpIcon);
    //ou assim: bHelp = new JButton("Manual",HelpIcon);
  bHelp.setText("Manual");        
  ActionListener listHelp = new help();
  bHelp.addActionListener(listHelp);
    }
 
  public JComponent buildInfo(boolean grouped) {    
   info();
     FormLayout layout = new FormLayout(  
     "pref, 4dlu, 80dlu, 2dlu, 70dlu, 2dlu, 35dlu, 2dlu, 35dlu",
     "p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p");  
            
      if (grouped) { 
        layout.setRowGroups(new int[][] { { 1, 3, 5, 7, 9, 11, 13} });
     }
        
  JPanel panelInfo = new JPanel(layout);
    panelInfo.setBorder(Borders.DIALOG_BORDER);
  CellConstraints cc = new CellConstraints();
    panelInfo.add(bHelp, cc.xy(5, 3));
    panelInfo.add(new JLabel("<html><body><font size=2>Por: <i>Francis Rodrigues</i></font></body></html>"), cc.xy(5, 7));
    panelInfo.add(bSite,  cc.xy(5, 9));
       return panelInfo;
   } 
         
 public class meuSite implements ActionListener {
     public void actionPerformed(ActionEvent e) {
    try {
      URI uri = new URI("http://www.guj.com.br");
      Desktop desktop = null;
      if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
      }
      if (desktop != null)
        desktop.browse(uri);
    } catch (IOException ioe) {
      ioe.printStackTrace();
    } catch (URISyntaxException use) {
      use.printStackTrace();
    }
}
} //fim da classe meuSite

 public class help implements ActionListener {
     public void actionPerformed(ActionEvent e) {
    try {
      URI uri = new URI("manual/help.htm");
      Desktop desktop = null;
      if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
      }
      if (desktop != null)
        desktop.browse(uri);
    } catch (IOException ioe) {
      ioe.printStackTrace();
    } catch (URISyntaxException use) {
      use.printStackTrace();
    } //fim do try e catch    
}
} 
}

Obrigado pela atenção.

Criado 27 de maio de 2008
Respostas 0
Participantes 1