fmeyer
Maio 17, 2005, 11:40pm
#1
jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 5, 1);
essa linha tem erro … feche os parenteses
jPanel2.setPreferredSize(new java.awt.Dimension(400, 16);
essa linha tb tem erro … feche os parenteses
ManipArq arq = new ManipArq();
onde vc definiu esse tipo ManipArg ???
fmeyer
Maio 18, 2005, 12:37am
#2
oque voce fez foi estender javax.swing.JPanel
mas não é o Jpanel q faz aparecer aquela janelinha … Extenda o JFrame ou crie uma classe que estenda JFrame e use o metodo getcontentpane.add() …
Sou iniciante em java, e tenho uma dúvida básica com Interface gráfica…Se puderem me ajudar!!!
Compila mas não roda…ou roda e não mostra a interface…
este é a menssagem: [size=18]Command completed. No files needed to be created, changed, or deleted.[/size]
Código:
import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io .*;
public class Interface extends javax.swing.JPanel {
public Interface() {
// initComponents();
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
botao1 = new javax.swing.JButton();
botao2 = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
textA = new javax.swing.JTextArea();
setLayout(new java.awt.BorderLayout());
setPreferredSize(new java.awt.Dimension(400, 200));
jPanel1.setPreferredSize(new java.awt.Dimension(400, 25));
jPanel1.setMinimumSize(new java.awt.Dimension(20, 20));
botao1.setText("Gravar");
botao1.setPreferredSize(new java.awt.Dimension(50, 25));
botao1.setMargin(new java.awt.Insets(4, 14, 4, 14));
botao1.setMinimumSize(new java.awt.Dimension(10, 20));
botao1.setAutoscrolls(true);
botao1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
botao1ActionPerformed(evt);
}
});
jPanel1.add(botao1);
botao2.setText("Ler");
botao2.setPreferredSize(new java.awt.Dimension(50, 25));
botao2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2, true));
botao2.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
botao2.setActionCommand("Ler");
botao2.setAutoscrolls(true);
botao2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
botao2ActionPerformed(evt);
}
});
jPanel1.add(botao2);
add(jPanel1, java.awt.BorderLayout.CENTER);
jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 5, 18));
jPanel2.setPreferredSize(new java.awt.Dimension(400, 168));
textA.setTabSize(5);
textA.setPreferredSize(new java.awt.Dimension(390, 145));
jPanel2.add(textA);
add(jPanel2, java.awt.BorderLayout.SOUTH);
}
private void botao1ActionPerformed(java.awt.event.ActionEvent evt) {
String texto = new String();
texto=textA.getText();
ManipArq arq = new ManipArq ();
arq.escreveArquivo("d:\\docs java\\arquivo.txt",texto);
}
private void botao2ActionPerformed(java.awt.event.ActionEvent evt) {
// Add your handling code here:
}
// Variables declaration - do not modify
private javax.swing.JButton botao1;
private javax.swing.JButton botao2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JTextArea textA;
// End of variables declaration
public static void main(String args[])
{ Interface i = new Interface();
// try{
i.initComponents();
i.setVisible(true); //Acho que o erro é aqui…
// }catch(IOException e){
// }
}
}
Valeu galera…
Aí scottys0 , esses erros não existem…é que eu apaguei trechos dispensaveis do código…e ManipArq é uma classe que carrega métodos de manipulação de arquivos…Me parece que apenas não aparece a interface, usei o FORM do netBeans para a interface…sou inexperiente em java…Estou postando o código inteiro:
import java.io.IOException;
import java.io .*;
public class Interface extends javax.swing.JPanel {
/** Creates new form Interface */
public Interface() {
// initComponents();
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
botao1 = new javax.swing.JButton();
botao2 = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
textA = new javax.swing.JTextArea();
setLayout(new java.awt.BorderLayout());
setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 255)));
setPreferredSize(new java.awt.Dimension(400, 200));
jPanel1.setPreferredSize(new java.awt.Dimension(400, 25));
jPanel1.setMinimumSize(new java.awt.Dimension(20, 20));
botao1.setText("Gravar");
botao1.setBackground(new java.awt.Color(160, 160, 160));
botao1.setAlignmentY(4.0F);
botao1.setAlignmentX(2.0F);
botao1.setPreferredSize(new java.awt.Dimension(50, 25));
botao1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2, true));
botao1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
botao1.setMargin(new java.awt.Insets(4, 14, 4, 14));
botao1.setMinimumSize(new java.awt.Dimension(10, 20));
botao1.setAutoscrolls(true);
botao1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
botao1ActionPerformed(evt);
}
});
jPanel1.add(botao1);
botao2.setText("Ler");
botao2.setBackground(new java.awt.Color(160, 160, 160));
botao2.setAlignmentY(4.0F);
botao2.setAlignmentX(2.0F);
botao2.setPreferredSize(new java.awt.Dimension(50, 25));
botao2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2, true));
botao2.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
botao2.setActionCommand("Ler");
botao2.setAutoscrolls(true);
botao2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
botao2ActionPerformed(evt);
}
});
jPanel1.add(botao2);
add(jPanel1, java.awt.BorderLayout.CENTER);
jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 5, 18));
jPanel2.setPreferredSize(new java.awt.Dimension(400, 168));
textA.setTabSize(5);
textA.setPreferredSize(new java.awt.Dimension(390, 145));
jPanel2.add(textA);
add(jPanel2, java.awt.BorderLayout.SOUTH);
}
private void botao1ActionPerformed(java.awt.event.ActionEvent evt) {
String texto = new String();
texto=textA.getText();
ManipArq arq = new ManipArq ();
arq.escreveArquivo("d:\\docs java\\arquivo.txt",texto);
}
private void botao2ActionPerformed(java.awt.event.ActionEvent evt) {
// Add your handling code here:
}
public static void main(String args[])
{ Interface i = new Interface();
// try{
i.initComponents();
i.setVisible(true);
// }catch(Exception e){
// }
}
// Variables declaration - do not modify
private javax.swing.JButton botao1;
private javax.swing.JButton botao2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JTextArea textA;
// End of variables declaration
}