Buscar
Social
Ofertas laborales ES

Foro sobre Java SE > Ayuda con JFrames en eclipse

Hola amigos! Tengo una duda con los frames en eclipse.
Estoy creando un programa para hacer un "Quizz". El código está todo entero perfecto, los frames igual. El problema que tengo es que no se como enlazar el frame a mi main. Cuando ejecuto el programa, todo va bien, pero no me sale la interfaz del programa.
Alguna sugerencia?

noviembre 5, 2014 | Registered Commenternercrom

Sugerencia: publica el código de ese main, y también al menos el constructor de ese JFrame principal.

noviembre 5, 2014 | Registered Commenterchoces

Dejar de usar Eclipse y empezar a usar Netbeans.

noviembre 6, 2014 | Unregistered CommenterTrolldamire

Yo siempre he utilizado NetBeans, pero me obligan a usar eclipse en la carrera :)
Código del main:
package database;

public class Run {
public static void main(String[] args) {
Database base = new Database();
base.connect();
int number_of_teams=base.countTeams();
}
}

Frame principal:
/*
* Created by JFormDesigner on Tue Nov 04 15:20:35 CET 2014
*/

package database;

import java.awt.event.*;

import javax.swing.*;

/**
* @author Pablo Escalante
*/
public class Frame_2 extends JPanel {
public Frame_2() {
initComponents();
}

private void thisMouseClicked(MouseEvent e) {
// TODO add your code here
}

private void button1MouseClicked(MouseEvent e) {
// TODO add your code here
}

private void button1ActionPerformed(ActionEvent e) {
Database base = new Database();
int teams,members_per_team,suscribe_money;
int amount_rounds;
String name, date, hour,place;
name=textField1.getText();
place=textField2.getText();
date=textField3.getText();
hour=textField6.getText();
members_per_team=Integer.parseInt(textField5.getText());
teams=Integer.parseInt(textField6.getText());
suscribe_money=Integer.parseInt(textField7.getText());
amount_rounds=Integer.parseInt(textField8.getText());
int i;
i=0;
if (teams>0 && members_per_team>0 && suscribe_money>0 && date!=null && hour !=null && amount_rounds>0){
base.quizCreator(name, place,date,hour, members_per_team, teams, suscribe_money);
for (i=amount_rounds; i>=0; i--){
Frame_3 open =new Frame_3();
open.setVisible(true);
}
}else{
JOptionPane.showMessageDialog(null,"Insert correct datas in the fields");
}
}

private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
// Generated using JFormDesigner Evaluation license - Pablo Escalante
label1 = new JLabel();
label2 = new JLabel();
label3 = new JLabel();
textField1 = new JTextField();
textField2 = new JTextField();
textField3 = new JTextField();
label4 = new JLabel();
textField4 = new JTextField();
button1 = new JButton();
label5 = new JLabel();
textField5 = new JTextField();
label6 = new JLabel();
textField6 = new JTextField();
label7 = new JLabel();
textField7 = new JTextField();
label8 = new JLabel();
textField8 = new JTextField();

//======== this ========
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
thisMouseClicked(e);
}
});

// JFormDesigner evaluation mark
setBorder(new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
"JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER,
javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12),
java.awt.Color.red), getBorder())); addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});


//---- label1 ----
label1.setText("Name");

//---- label2 ----
label2.setText("Place");

//---- label3 ----
label3.setText("Date(mm/dd/year)");

//---- label4 ----
label4.setText("Maximum amounts of teams");

//---- button1 ----
button1.setText("Ok");
button1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
button1MouseClicked(e);
}
});
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
button1ActionPerformed(e);
button1ActionPerformed(e);
}
});

//---- label5 ----
label5.setText("Maximum amount of members per team");

//---- label6 ----
label6.setText("Hour");

//---- label7 ----
label7.setText("Suscribe Money per team");

//---- label8 ----
label8.setText("Amount of rounds");

GroupLayout layout = new GroupLayout(this);
setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup()
.addGroup(layout.createSequentialGroup()
.addContainerGap(36, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup()
.addComponent(label1, GroupLayout.PREFERRED_SIZE, 96, GroupLayout.PREFERRED_SIZE)
.addComponent(label2, GroupLayout.PREFERRED_SIZE, 115, GroupLayout.PREFERRED_SIZE)
.addComponent(label6, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
.addComponent(label3))
.addGap(104, 104, 104)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
.addComponent(textField3, GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
.addComponent(textField1, GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
.addComponent(textField2, GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
.addComponent(textField6, GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE))
.addGap(129, 129, 129))
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup()
.addComponent(label7, GroupLayout.PREFERRED_SIZE, 129, GroupLayout.PREFERRED_SIZE)
.addComponent(label5, GroupLayout.PREFERRED_SIZE, 209, GroupLayout.PREFERRED_SIZE)
.addComponent(label4, GroupLayout.PREFERRED_SIZE, 148, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
.addComponent(textField5, GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE)
.addComponent(textField4, GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE)
.addComponent(textField7, GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE))
.addGap(128, 128, 128))
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(label8, GroupLayout.PREFERRED_SIZE, 121, GroupLayout.PREFERRED_SIZE)
.addGap(98, 98, 98)
.addComponent(textField8, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(button1)
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup()
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(label1, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
.addComponent(textField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(label2)
.addComponent(textField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(9, 9, 9)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(textField3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(label3))
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup()
.addComponent(label6)
.addComponent(textField6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup()
.addComponent(textField4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(label4, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
.addGap(9, 9, 9)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(label5)
.addComponent(textField5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(textField7, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(label7))
.addGroup(layout.createParallelGroup()
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(button1))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(label8)
.addComponent(textField8, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
.addContainerGap())
);
// JFormDesigner - End of component initialization //GEN-END:initComponents
}

// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
// Generated using JFormDesigner Evaluation license - Pablo Escalante
private JLabel label1;
private JLabel label2;
private JLabel label3;
private JTextField textField1;
private JTextField textField2;
private JTextField textField3;
private JLabel label4;
private JTextField textField4;
private JButton button1;
private JLabel label5;
private JTextField textField5;
private JLabel label6;
private JTextField textField6;
private JLabel label7;
private JTextField textField7;
private JLabel label8;
private JTextField textField8;
// JFormDesigner - End of variables declaration //GEN-END:variables
}

Quiero que al ejecutar el programa aparezcan los Frames, y no se como enlazarlos al main principal

noviembre 7, 2014 | Registered Commenternercrom

En tu main no se crea ninguna instancia de clases Swing (que se vea, al menos)
Esa clase que llamas Frame_2 es un JPanel. Los JPanel no se pueden visualizar directamente, sino añadiéndolos a un JFrame.

noviembre 7, 2014 | Registered Commenterchoces

public class NewMain {

/**
@param args the command line arguments
*/
public static void main(String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new NewJFrame().setVisible(true);
}
});
}

}

noviembre 7, 2014 | Registered Commenterchoces

<p>
@author Carlos Hoces
*/
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() {

jPanel1 = new javax.swing.JPanel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Este es el JFrame principal");

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Este es un JPanel"));

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 368, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 245, Short.MAX_VALUE)
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);

pack();
}// </editor-fold>

// Variables declaration - do not modify
private javax.swing.JPanel jPanel1;
// End of variables declaration
}

noviembre 7, 2014 | Registered Commenterchoces

Entiendo. Una vez creado el Panel principal, como puedo enlazar mis frames?

noviembre 7, 2014 | Registered Commenternercrom

Necesitas añadirlos al JFrame. Yo uso NetBeans no JFormDesigner.

noviembre 7, 2014 | Registered Commenterchoces