Jump to content
Fórum Script Brasil
  • 0

Como importar classe dentro de um jFrame?


MaikeES

Question

Pessoal tenho um JFrame e um arquivos de classes no meu projeto gostaria de importar meu arquivo de classes para dentro do meu JFrame como posso fazer isto?

public class FrmPrincipal extends javax.swing.JFrame{

/**

* Creates new form FrmPrincipal

*/

public FrmPrincipal() {

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() {

jMenuBar1 = new javax.swing.JMenuBar();

cadastros = new javax.swing.JMenu();

cadastroInsituicao = new javax.swing.JMenuItem();

cadastroProfessores = new javax.swing.JMenuItem();

cadastroPerguntas = new javax.swing.JMenuItem();

cadastroRespostas = new javax.swing.JMenuItem();

jMenu3 = new javax.swing.JMenu();

jMenu5 = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jMenuBar1.setToolTipText("");

cadastros.setMnemonic('c');

cadastros.setText("Cadastros");

cadastroInsituicao.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));

cadastroInsituicao.setText("Instituições");

cadastroInsituicao.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

cadastroInsituicaoActionPerformed(evt);

}

});

cadastros.add(cadastroInsituicao);

cadastroProfessores.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));

cadastroProfessores.setText("Professores");

cadastroProfessores.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

cadastroProfessoresActionPerformed(evt);

}

});

cadastros.add(cadastroProfessores);

cadastroPerguntas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));

cadastroPerguntas.setText("Perguntas");

cadastroPerguntas.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

cadastroPerguntasActionPerformed(evt);

}

});

cadastros.add(cadastroPerguntas);

cadastroRespostas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));

cadastroRespostas.setText("Respostas");

cadastros.add(cadastroRespostas);

jMenuBar1.add(cadastros);

jMenu3.setMnemonic('r');

jMenu3.setText("Resultados");

jMenu3.setMargin(new java.awt.Insets(0, 5, 0, 0));

jMenuBar1.add(jMenu3);

jMenu5.setMnemonic('s');

jMenu5.setText("Sair");

jMenu5.setMargin(new java.awt.Insets(0, 10, 0, 0));

jMenu5.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

jMenu5MouseClicked(evt);

}

});

jMenu5.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jMenu5ActionPerformed(evt);

}

});

jMenuBar1.add(jMenu5);

setJMenuBar(jMenuBar1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGap(0, 294, Short.MAX_VALUE)

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGap(0, 279, Short.MAX_VALUE)

);

pack();

}// </editor-fold>

private void cadastroInsituicaoActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

}

private void cadastroPerguntasActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

}

private void jMenu5ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

}

private void jMenu5MouseClicked(java.awt.event.MouseEvent evt) {

System.exit(0);// TODO add your handling code here:

}

private void cadastroProfessoresActionPerformed(java.awt.event.ActionEvent evt) {

new FrmProfessores().show(); // TODO add your handling code here:

}

/**

* @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 http://download.oracle.com/javase/tutorial...dfeel/plaf.html

*/

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(FrmPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(FrmPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(FrmPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(FrmPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

}

//</editor-fold>

/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() {

@Override

public void run() {

new FrmPrincipal().setVisible(true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JMenuItem cadastroInsituicao;

private javax.swing.JMenuItem cadastroPerguntas;

private javax.swing.JMenuItem cadastroProfessores;

private javax.swing.JMenuItem cadastroRespostas;

private javax.swing.JMenu cadastros;

private javax.swing.JMenu jMenu3;

private javax.swing.JMenu jMenu5;

private javax.swing.JMenuBar jMenuBar1;

// End of variables declaration

}

public class funcao{

public static void exibir(String sTexto) {

JOptionPane.showMessageDialog(null, sTexto);

}

public static void conexaoBd(String sBanco, String sUsuario, String sSenha)

{

Connection cConexao;

try{

cConexao = DriverManager.getConnection("jdbc:mysql://localhost/"+sBanco,sUsuario,sSenha);

exibir("Conexão realizada com sucesso"); //Exibe mensagem de sucesso caso banco seja conectado

}catch(SQLException | HeadlessException e){

exibir("Sua conexão não pode ser realizada"); // exibe mensagem de erro caso classe principal não consiga ser executada

}

}

}

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152k
    • Total Posts
      651.5k
×
×
  • Create New...