Javax

Sou iniciante em Java, estou tentando rodar um exemplo de um livro, mas está dando erro em tudo q diz respeito a JFrame, isso faz parte de um pacote chamado Javax? onde encontro ele?

ICE Man , poste o código do seu programa , fiuca mais facil.

Vc deve ter se esquecido de importar a classe javax que é referente aos “objetos” swing(JFrame, JPanel, JButton JInternalFrame e etc…)

tente fazer isso:


import javax.swing.*;
import javax.swing.event.*

public class Minha classe{

\

}

Agora vai funcionar!!!

E ai blz?

Então… coloque o fonte. Vc importou o javax.swing.JFrame? Ou pode ser que vc nã tenha configurado o CLASSPATH…

:smiley:

bom eu achei na internet o tal pacote, como instalo ele?

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.html.*;


// O MiniBrowser.
public class MiniBrowser extends Jframe
  implements HyperlinkListener

{
  // Esses são os botões para iterar pela lista de páginas.
  private JButton backButton, forwardButton;

  // Campo de texto de localização da página.
  private JTextField locationTextField;

  // Painel dditor para exibir as páginas.
  private JEditorPane displayEditorPane;

  // Lista de páginas que foram visitadas do navegador.
  private ArrayList pageList = new ArrayList();

  // Construtor para o MiniBrowser.
  public MiniBrowser()
  {


    // Configura o título da aplicação.
    super("MiniBrowser");


    // Configura o tamanho da janela.
    setSize(640, 480);

    // Trata eventos de fechamento.
    addWindowListener(new WindowAdapter() {
      public void WindowClosing(WindowEvent e) {
        actionExit();
      }
  });

  // Configura o menu File.
  JMenuBar menuBar = JmenuBar();
  JMenu fileMenu = new JMenu("File");
  fileMenu.SetMnemonic(KeyEvent.VK_F);
  JMenuItem fileExitMenuItem = new JMenuItem("Exit",
    KeyEvent.VK_X);
  fileExitMenuItem.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      actionExit();
    }
  });
  fileMenu.add(fileExitMenuItem);
  menuBar.add(fileMenu);
  setJMenuBar(menuBar);

  // Configura o painel de botões.
  JPanel buttonPanel = new Jpanel();
  backButton = new JButton("< Back");
  backButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      actionBack();
    }
  });
  backButton.setEnabled(false);
  buttonPanel.add(backButton);
  forwardButton = new JButton("Forward >");
  forwardButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      actionForward();
    }
  });
  forwardButton.setEnabled(false);
  buttonPanel.add(forwardButton);
  locationTextField = new JtextField(35);
  locationTextField.addKeyListener(new KeyAdapter() {
    public void KeyReleased(KeyEvent e) {
      if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        actionGo();
      }
    }
  });
  buttonPanel.add(locationTextField);
  JButton goButton = new JButton("GO");
  goButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      actionGo();
    }
  });
  buttonPanel.add(goButton);

  // Configura a exibição da página.
  displayEditorPane = new JEditorPane();
  displayEditorPane.setContentType("text/html");
  displayEditorPane.setEditable(false);
  displayEditorPane.addHyperlinkListener(this);
 
  getContentPane().setLayout(new BorderLayout());
  getContentPane().add(buttonPanel, BorderLayout.NORTH);
  getContentPane().add(new JScrollPane(displayEditorPane),
    BorderLayout.CENTER);
}

// Sai desse programa.
private void actionExit() {
  System.exit(0);
}

// Volta à página visualizada antes da página atual.
private void actionBack() {
  URL currentURL = displayEditorPane.getPage();
  int pageIndex = pageList.indexOf(currentUrl.toString());
  try {
    showPage(
      new URL((String) pageList.get(pageIndex - 1)), false);
    }
    catch (Exception e) {}
}

// Avança até a página visualizada depois da página atual.
private void actionForward() {
  URL currentUrl = displayEditorPane.getPage();
  int pageIndex = pageList.indexOf(currentUrltoString());
  try {
    showPage(
      new URL((String) pageList.get(pageIndex + 1)), false);

  }
  catch (Exception e) {}
}

// Carrega e mostra a página especificada no campo de texto de localização.
private void actionGo() {
  URL verifiedUrl = verifyUrl(locationTextField.getText());
  if (verifiedUrl != null) {
    showPage(verifiedUrl, true);
  } else {
    showError("Invalid URL");
  }
}

// Mostra a caixa de diálogo com menssagem de erro.
private void showError(String errorMessage) {
  JOptionPane.showMessageDialog(this, errorMessage,
    "Error", JOtionPane.ERROR_MESSAGE);

}

// Verifica o formato do URL.
private URL verifyUrl(String url) {
  // Somente permite URLs de HTTP.
  if (!url.toLowerCase().startWith("http://"))
    return null;

  // Verfica o formato de URL.
  URL verifiedUrl = null;
  try {
    verifiedUrl = new URL(url);
  } catch(Exception e) {
    return null;
  }

  return verifiedUrl;

}

/* Mostra a página especificada e adiciona a ela a 
lista de páginas, se especificada. */
private void showPage(URL pageUrl, boolean addToList)
{
// Mostra o cursor com a forma de uma ampulheta enquanto a varredura está em andamento.
  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

  try {
    // Obtém o URL da página que está sendo atualmente exibida.
    URL currentUrl = displayEditorPane.getPage();
    
    // Carrega e exibe a página especificada.
    displayEditorPane.setPage(pageUrl);
  
    // Obtém o URL da nova página que está sendo exibida.
    URL newUrl = displayEditorPane.getPage();

    // Adicionaa página à lista se especificado.
     if (addToList) {
       int listSize = pageList.size();
       if (listSize > 0) {
         int pageIndex =
           pageList.indexOf(currentUrl.toString());
         if (pageIndex < listSize - 1) {
           for (int i = listSize - 1; i > pageIndex; i--) {
             pageList.remove(i);
           }
         }
       }
       pageList.add(newUrl.toString());
     }
   
     // Atualiza o campo de localização de texto com o URL da página atual.
     locationTextField.setText(newUrl.toString());

     // Atualiza os botões com base na página que está sendo exibida.
     updateButtons();
  }
  catch (Exception e)
  {
    // Mostra mensagem de erro.
    showError("Unable to load page");
  }
  finally
  {
    // Retorna ao cursor padrão.
    setCursor(Cursor.getDefaultCursor());
      
  }
}

/* Atualiza os botões Back e Forward com base na 
  página que está sendo exibida. */
private void updateButtons() {
  if (pageList.size() < 2) {
    backButton.setEnabled(false);
    forwardButton.setEnabled(false);
  } else {
    URL currentUrl = displayEditorPane.getPage();
    int pageIndex = pageList.indexOf(CurrentUrl.toString());
    backButton.setEnabled(pageIndex > 0);
    forwardButton.setEnabled(
      pageIndex < (pageList.size() - 1));
  }
}

// Trata os hyperlinks que estão sendo clicados.
public void hyperlinkUpdate(HyperlinkEvent event){ 
  HyperlinkEvent.EventType eventType = event.getEventType();
    if (eventType == HyperlinkEvent.EventType.ACTIVATED) {
      if (event instanceof HTMLFrameHyperlinkEvent) {
        HTMLFrameHyperlinkEvent linkEvent =
          (HTMLFrameHyperlinkEvent) event;
        HTMLDocument document = 
          (HTMLDocument) displayEditorPane.getDocument();
        document.processHTMLFrameHyperlinkEvent(linkEvent);
      } else {
          showpage(event.getURL(), true);
      }
    }
  }

  // Executa o MiniBrowser. 
  public static void main(String[] args) {
    MiniBrowser browser = new MiniBrowser();
    browser.show();
  }
}

EDITADO POR FelipeSS.

Blz kara… Java é sensitive case, então letra maiuscula e minuscula diferem.

Segue o código corrigido:

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.html.*;


// O MiniBrowser.
public class MiniBrowser extends JFrame
  implements HyperlinkListener

{
  // Esses são os botões para iterar pela lista de páginas.
  private JButton backButton, forwardButton;

  // Campo de texto de localização da página.
  private JTextField locationTextField;

  // Painel dditor para exibir as páginas.
  private JEditorPane displayEditorPane;

  // Lista de páginas que foram visitadas do navegador.
  private ArrayList pageList = new ArrayList();

  // Construtor para o MiniBrowser.
  public MiniBrowser()
  {


    // Configura o título da aplicação.
    super("MiniBrowser");


    // Configura o tamanho da janela.
    setSize(640, 480);

    // Trata eventos de fechamento.
    addWindowListener(new WindowAdapter() {
      public void WindowClosing(WindowEvent e) {
        actionExit();
      }
  });

  // Configura o menu File.
  JMenuBar menuBar = new JMenuBar();
  JMenu fileMenu = new JMenu("File");
  fileMenu.setMnemonic(KeyEvent.VK_F);
  JMenuItem fileExitMenuItem = new JMenuItem("Exit",
    KeyEvent.VK_X);
  fileExitMenuItem.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      actionExit();
    }
  });
  fileMenu.add(fileExitMenuItem);
  menuBar.add(fileMenu);
  setJMenuBar(menuBar);

  // Configura o painel de botões.
  JPanel buttonPanel = new JPanel();
  backButton = new JButton("< Back");
  backButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      actionBack();
    }
  });
  backButton.setEnabled(false);
  buttonPanel.add(backButton);
  forwardButton = new JButton("Forward >");
  forwardButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      actionForward();
    }
  });
  forwardButton.setEnabled(false);
  buttonPanel.add(forwardButton);
  locationTextField = new JTextField(35);
  locationTextField.addKeyListener(new KeyAdapter() {
    public void KeyReleased(KeyEvent e) {
      if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        actionGo();
      }
    }
  });
  buttonPanel.add(locationTextField);
  JButton goButton = new JButton("GO");
  goButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      actionGo();
    }
  });
  buttonPanel.add(goButton);

  // Configura a exibição da página.
  displayEditorPane = new JEditorPane();
  displayEditorPane.setContentType("text/html");
  displayEditorPane.setEditable(false);
  displayEditorPane.addHyperlinkListener(this);

  getContentPane().setLayout(new BorderLayout());
  getContentPane().add(buttonPanel, BorderLayout.NORTH);
  getContentPane().add(new JScrollPane(displayEditorPane),
    BorderLayout.CENTER);
}

// Sai desse programa.
private void actionExit() {
  System.exit(0);
}

// Volta à página visualizada antes da página atual.
private void actionBack() {
  URL currentURL = displayEditorPane.getPage();
  int pageIndex = pageList.indexOf(currentURL.toString());
  try {
    showPage(
      new URL((String) pageList.get(pageIndex - 1)), false);
    }
    catch (Exception e) {}
}

// Avança até a página visualizada depois da página atual.
private void actionForward() {
  URL currentUrl = displayEditorPane.getPage();
  int pageIndex = pageList.indexOf(currentUrl.toString());
  try {
    showPage(
      new URL((String) pageList.get(pageIndex + 1)), false);

  }
  catch (Exception e) {}
}

// Carrega e mostra a página especificada no campo de texto de localização.
private void actionGo() {
  URL verifiedUrl = verifyUrl(locationTextField.getText());
  if (verifiedUrl != null) {
    showPage(verifiedUrl, true);
  } else {
    showError("Invalid URL");
  }
}

// Mostra a caixa de diálogo com menssagem de erro.
private void showError(String errorMessage) {
  JOptionPane.showMessageDialog(this, errorMessage,
    "Error", JOptionPane.ERROR_MESSAGE);

}

// Verifica o formato do URL.
private URL verifyUrl(String url) {
  // Somente permite URLs de HTTP.
  if (!url.toLowerCase().startsWith("http://"))
    return null;

  // Verfica o formato de URL.
  URL verifiedUrl = null;
  try {
    verifiedUrl = new URL(url);
  } catch(Exception e) {
    return null;
  }

  return verifiedUrl;

}

/* Mostra a página especificada e adiciona a ela a
lista de páginas, se especificada. */
private void showPage(URL pageUrl, boolean addToList)
{
// Mostra o cursor com a forma de uma ampulheta enquanto a varredura está em andamento.
  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

  try {
    // Obtém o URL da página que está sendo atualmente exibida.
    URL currentUrl = displayEditorPane.getPage();

    // Carrega e exibe a página especificada.
    displayEditorPane.setPage(pageUrl);

    // Obtém o URL da nova página que está sendo exibida.
    URL newUrl = displayEditorPane.getPage();

    // Adicionaa página à lista se especificado.
     if (addToList) {
       int listSize = pageList.size();
       if (listSize > 0) {
         int pageIndex =
           pageList.indexOf(currentUrl.toString());
         if (pageIndex < listSize - 1) {
           for (int i = listSize - 1; i > pageIndex; i--) {
             pageList.remove(i);
           }
         }
       }
       pageList.add(newUrl.toString());
     }

     // Atualiza o campo de localização de texto com o URL da página atual.
     locationTextField.setText(newUrl.toString());

     // Atualiza os botões com base na página que está sendo exibida.
     updateButtons();
  }
  catch (Exception e)
  {
    // Mostra mensagem de erro.
    showError("Unable to load page");
  }
  finally
  {
    // Retorna ao cursor padrão.
    setCursor(Cursor.getDefaultCursor());

  }
}

/* Atualiza os botões Back e Forward com base na
  página que está sendo exibida. */
private void updateButtons() {
  if (pageList.size() < 2) {
    backButton.setEnabled(false);
    forwardButton.setEnabled(false);
  } else {
    URL currentUrl = displayEditorPane.getPage();
    int pageIndex = pageList.indexOf(currentUrl.toString());
    backButton.setEnabled(pageIndex > 0);
    forwardButton.setEnabled(
      pageIndex < (pageList.size() - 1));
  }
}

// Trata os hyperlinks que estão sendo clicados.
public void hyperlinkUpdate(HyperlinkEvent event){
  HyperlinkEvent.EventType eventType = event.getEventType();
    if (eventType == HyperlinkEvent.EventType.ACTIVATED) {
      if (event instanceof HTMLFrameHyperlinkEvent) {
        HTMLFrameHyperlinkEvent linkEvent =
          (HTMLFrameHyperlinkEvent) event;
        HTMLDocument document =
          (HTMLDocument) displayEditorPane.getDocument();
        document.processHTMLFrameHyperlinkEvent(linkEvent);
      } else {
          showPage(event.getURL(), true);
      }
    }
  }

  // Executa o MiniBrowser.
  public static void main(String[] args) {
    MiniBrowser browser = new MiniBrowser();
    browser.show();
  }
}