To com problema na parte de variaveis compartilhadas com outras classes
Aqui está meu código da classe mãe:
[code]package code;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
public class Home {
public List<Double> altura = new ArrayList<Double>();
public void consultar() {
altura.add(1.56);
altura.toArray();
double maior = altura.get(0);
double menor = altura.get(0);
for (double valor : altura) {
if (maior < valor) {
maior = valor;
}
if (menor > valor) {
menor = valor;
}
JOptionPane.showMessageDialog(null, "O Maior é: " + maior );
JOptionPane.showMessageDialog(null, "O Menor é: " + menor);
}
}
public void adicionar() {
double novoValor = Double.parseDouble(JOptionPane.showInputDialog(
"Informe uma Altura abaixo: "));
altura.add(novoValor);
}
}[/code]
e aqui a da interface que está vazia!!
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package code;
/**
*
* @author bruno
*/
public class Interface extends javax.swing.JFrame {
/**
* Creates new form Interface
*/
public Interface() {
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() {
addButton = new javax.swing.JButton();
delButton = new javax.swing.JButton();
consultarButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
saidaArea = new javax.swing.JTextArea();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addButton.setText("Adicionar +");
addButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addButtonActionPerformed(evt);
}
});
delButton.setText("Excluir ø");
consultarButton.setText("← Consultar →");
saidaArea.setColumns(20);
saidaArea.setRows(5);
jScrollPane1.setViewportView(saidaArea);
jLabel1.setText("Men's Size,");
jLabel2.setText("ßeta 0.01");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(43, 43, 43)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addGroup(layout.createSequentialGroup()
.addComponent(addButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(delButton, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(consultarButton)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(57, 57, 57))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jLabel2))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {addButton, consultarButton, delButton});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(addButton)
.addComponent(delButton))
.addGap(26, 26, 26)
.addComponent(consultarButton)
.addGap(34, 34, 34)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
.addComponent(jLabel2))
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {addButton, consultarButton, delButton});
pack();
}// </editor-fold>
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
//<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/uiswing/lookandfeel/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(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Interface().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton addButton;
private javax.swing.JButton consultarButton;
private javax.swing.JButton delButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea saidaArea;
// End of variables declaration
}
Eu sei que existen diversos tutoriais inclusive aqui mas, tentei de tudo (mas resolvi deixar limpa a Classe), e não me acerto com esse List ai,
e se for fazer com array não vai ser do propósito do programa,!
Obrigado!