Baixe o app para aproveitar ainda mais
Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original
aula07_ex2_LeituraJList/build.xml Builds, tests, and runs the project aula07_ex2_LeituraJList. aula07_ex2_LeituraJList/manifest.mf Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build aula07_ex2_LeituraJList/nbproject/build-impl.xml Must set src.dir Must set test.src.dir Must set build.dir Must set dist.dir Must set build.classes.dir Must set dist.javadoc.dir Must set build.test.classes.dir Must set build.test.results.dir Must set build.classes.excludes Must set dist.jar Must set javac.includes No tests executed. Must set JVM to use for profiling in profiler.info.jvm Must set profiler agent JVM arguments in profiler.info.jvmargs.agent Must select some files in the IDE or set javac.includes To run this application from the command line without Ant, try: java -jar "${dist.jar.resolved}" Must select one file in the IDE or set run.class Must select one file in the IDE or set run.class Must select one file in the IDE or set debug.class Must select one file in the IDE or set debug.class Must set fix.includes This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set profile.class This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set run.class Must select some files in the IDE or set test.includes Must select one file in the IDE or set run.class Must select one file in the IDE or set applet.url Must select some files in the IDE or set javac.includes Some tests failed; see details above. Must select some files in the IDE or set test.includes Some tests failed; see details above. Must select some files in the IDE or set test.class Must select some method in the IDE or set test.method Some tests failed; see details above. Must select one file in the IDE or set test.class Must select one file in the IDE or set test.class Must select some method in the IDE or set test.method Must select one file in the IDE or set applet.url Must select one file in the IDE or set applet.url aula07_ex2_LeituraJList/nbproject/genfiles.properties build.xml.data.CRC32=96771c7e build.xml.script.CRC32=5149ed40 build.xml.stylesheet.CRC32=8064a381@1.80.1.48 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=96771c7e nbproject/build-impl.xml.script.CRC32=f138427a nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 aula07_ex2_LeituraJList/nbproject/project.properties annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processor.options= annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: build.dir=build build.generated.dir=${build.dir}/generated build.generated.sources.dir=${build.dir}/generated-sources # Only compile against the classpath explicitly listed here: build.sysclasspath=ignore build.test.classes.dir=${build.dir}/test/classes build.test.results.dir=${build.dir}/test/results # Uncomment to specify the preferred debugger connection transport: #debug.transport=dt_socket debug.classpath=\ ${run.classpath} debug.test.classpath=\ ${run.test.classpath} # Os arquivos em build.classes.dir que devem ser exclu\u00eddos do jar de distribui\u00e7\u00e3o dist.archive.excludes= # This directory is removed when the project is cleaned: dist.dir=dist dist.jar=${dist.dir}/aula07_ex2_LeituraJList.jar dist.javadoc.dir=${dist.dir}/javadoc excludes= includes=** jar.compress=false javac.classpath= # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false javac.external.vm=true javac.processorpath=\ ${javac.classpath} javac.source=1.8 javac.target=1.8 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir} javac.test.processorpath=\ ${javac.test.classpath} javadoc.additionalparam= javadoc.author=false javadoc.encoding=${source.encoding} javadoc.noindex=false javadoc.nonavbar=false javadoc.notree=false javadoc.private=false javadoc.splitindex=true javadoc.use=true javadoc.version=false javadoc.windowtitle= main.class=aula07_ex1.Aula07_ex2 manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false platform.active=default_platform run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} # Space-separated list of JVM arguments used when running the project. # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. # To set system properties for unit tests define test-sys-prop.name=value: run.jvmargs= run.test.classpath=\ ${javac.test.classpath}:\ ${build.test.classes.dir} source.encoding=UTF-8 src.dir=src test.src.dir=test aula07_ex2_LeituraJList/nbproject/project.xml org.netbeans.modules.java.j2seproject aula07_ex2_LeituraJList aula07_ex2_LeituraJList/src/aula07_ex1/Aula07_ex2.java package aula07_ex1; public class Aula07_ex2 { public static void main(String[] args) { Empresa e = new Empresa(); e.iniciarEmpresa(); } } aula07_ex2_LeituraJList/src/aula07_ex1/Empresa.java package aula07_ex1; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; import java.util.Iterator; import java.util.StringTokenizer; import javax.swing.DefaultListModel; import javax.swing.ListModel; public class Empresa { //private Funcionario[] listaFuncionarios; private ArrayList<Funcionario> listaFuncionarios; private PessoaView viewP; protected String nomeArq = "D:\\funcionarios.txt"; public Empresa() { listaFuncionarios = new ArrayList<Funcionario>(); viewP = new PessoaView(); viewP.setListenerInserir(new InserirListener()); viewP.setListenerSalvar(new SalvarListener()); viewP.setListenerCarregar(new CarregarListener()); viewP.setNomeArq(nomeArq); } public void iniciarEmpresa(){ viewP.setVisible(true); } public class CarregarListener implements ActionListener{ @Override public void actionPerformed(ActionEvent ae) { try { viewP.limparLista(); nomeArq = viewP.getNomeArq(); listaFuncionarios.clear(); FileReader fr = new FileReader(nomeArq); BufferedReader br = new BufferedReader(fr); String linha = br.readLine(); while (linha !=null){ Funcionario f = new Funcionario(); f.carregar(linha); listaFuncionarios.add(f); viewP.addElementoLista(f); linha = br.readLine(); } br.close(); fr.close(); } catch (Exception e) { System.out.println("Deu m... Erro="+e); } } } public class InserirListener implements ActionListener{ @Override public void actionPerformed(ActionEvent ae) { String nome = viewP.getNome(); int idade = viewP.getIdade(); double salario = viewP.getSalario(); String cargo = viewP.getCargo(); Funcionario f = new Funcionario(salario, cargo, nome, idade); listaFuncionarios.add(f); ///--------------------/// viewP.addElementoLista(f); ///--------------------/// } } public class SalvarListener implements ActionListener{ @Override public void actionPerformed(ActionEvent ae) { //------------------// nomeArq = viewP.getNomeArq(); //------------------// Iterator<Funcionario> it = listaFuncionarios.iterator(); while(it.hasNext()){ Funcionario f = it.next(); //------------------// f.setNomeArq(nomeArq); f.setAppend(viewP.getApend()); //------------------// f.salvar(); } //----------------------------------------// } } } aula07_ex2_LeituraJList/src/aula07_ex1/Funcionario.java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package aula07_ex1; import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author alunoti */ public class Funcionario extends Pessoa { private double salario; private String cargo; public Funcionario(double salario, String cargo, String nomePessoa, int idade) { super(nomePessoa, idade); this.salario = salario; this.cargo = cargo; } public Funcionario() { super(); } @Override public String toString() { return nomePessoa + " - " + "R$ " + salario ; } public void salvar(){ FileWriter fw; try { fw = new FileWriter(nomeArq, this.append); fw.write(this.nomePessoa + "," + this.idade + "," + this.cargo + "," + this.salario + "\r\n"); fw.close(); } catch (IOException ex) { Logger.getLogger(Funcionario.class.getName()).log(Level.SEVERE, null, ex); } } public void carregar(){ try { FileReader fr = new FileReader(this.nomeArq); BufferedReader br = new BufferedReader(fr); String linha = br.readLine(); StringTokenizer st = new StringTokenizer(linha,","); this.nomePessoa = st.nextToken(); this.idade = Integer.parseInt(st.nextToken()); this.cargo = st.nextToken(); this.salario = Double.parseDouble(st.nextToken()); br.close(); fr.close(); } catch (Exception e) { System.out.println("Deu m... Erro="+e); } } public void carregar(String linha){ try { StringTokenizer st = new StringTokenizer(linha,","); this.nomePessoa = st.nextToken(); this.idade = Integer.parseInt(st.nextToken()); this.cargo = st.nextToken(); this.salario = Double.parseDouble(st.nextToken()); } catch (Exception e) { System.out.println("Deu m... Erro="+e); } } } aula07_ex2_LeituraJList/src/aula07_ex1/Pessoa.java package aula07_ex1; public abstract class Pessoa { protected String nomePessoa; protected int idade; protected String nomeArq = ""; protected boolean append = true; public Pessoa(String nomePessoa, int idade) { this.nomePessoa = nomePessoa; this.idade = idade; } public Pessoa(){ } public abstract void salvar(); public void setNomeArq(String nomeArq) { this.nomeArq = nomeArq; } public void setAppend(boolean append) { this.append = append; } } aula07_ex2_LeituraJList/src/aula07_ex1/PessoaView.form aula07_ex2_LeituraJList/src/aula07_ex1/PessoaView.java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package aula07_ex1; import java.awt.event.ActionListener; import javax.swing.AbstractListModel; import javax.swing.DefaultListModel; import javax.swing.JCheckBox; import javax.swing.JTextField; import javax.swing.ListModel; /** * * @author alunoti */ public class PessoaView extends javax.swing.JFrame { private DefaultListModel listaModel; public PessoaView() { listaModel = new DefaultListModel(); 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">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jTextField2 = new javax.swing.JTextField(); jTextField3 = new javax.swing.JTextField(); jTextField4 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButtonLoad = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); jListFuncionario = new javax.swing.JList(); jTextFieldNomeArq = new javax.swing.JTextField(); jLabelArq = new javax.swing.JLabel(); jCheckBoxApend = new javax.swing.JCheckBox(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("Nome: "); jLabel2.setText("Idade: "); jLabel3.setText("Salario: "); jLabel4.setText("Cargo: "); jButton1.setText("Inserir"); jButton2.setText("Salvar"); jButtonLoad.setText("Carregar"); jListFuncionario.setModel(this.listaModel); jScrollPane1.setViewportView(jListFuncionario); jLabelArq.setText("Nome Arq"); jCheckBoxApend.setSelected(true); jCheckBoxApend.setText("Apend Arquivo"); 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(19, 19, 19) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addComponent(jLabelArq, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextFieldNomeArq, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jButton1) .addGap(18, 18, 18) .addComponent(jCheckBoxApend)) .addGroup(layout.createSequentialGroup() .addComponent(jButtonLoad) .addGap(29, 29, 29) .addComponent(jButton2)) .addGroup(layout.createSequentialGroup() .addGap(3, 3, 3) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(jLabel3) .addComponent(jLabel4)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jTextField3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE) .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING)) .addComponent(jTextField4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addContainerGap(16, Short.MAX_VALUE)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(34, 34, 34) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(11, 11, 11) .addComponent(jButton1)) .addGroup(layout.createSequentialGroup() .addGap(18, 18, 18) .addComponent(jCheckBoxApend))) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelArq) .addComponent(jTextFieldNomeArq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButtonLoad) .addComponent(jButton2)) .addGap(18, 18, 18) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(23, 23, 23)) ); pack(); }// </editor-fold>//GEN-END:initComponents /** * @param args the command line arguments */ public void setListenerInserir(ActionListener x){ jButton1.addActionListener(x); } public void setListenerSalvar(ActionListener y){ jButton2.addActionListener(y); } public void setListenerCarregar(ActionListener z){ jButtonLoad.addActionListener(z); } public void addElementoLista(Object o){ listaModel.addElement(o); } public void limparLista(){ listaModel.clear(); } public boolean getApend() { return jCheckBoxApend.isSelected(); } public String getNome() { return jTextField1.getText(); } public int getIdade() { return Integer.parseInt(jTextField2.getText()); } public double getSalario() { return Double.parseDouble(jTextField3.getText()); } public String getCargo() { return jTextField4.getText(); } public String getNomeArq() { return jTextFieldNomeArq.getText(); } public void setNomeArq(String t) { this.jTextFieldNomeArq.setText(t); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButtonLoad; private javax.swing.JCheckBox jCheckBoxApend; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabelArq; private javax.swing.JList jListFuncionario; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; private javax.swing.JTextField jTextFieldNomeArq; // End of variables declaration//GEN-END:variables }
Compartilhar