kt1117 Opublikowano 5 Lipca 2011 Udostępnij Opublikowano 5 Lipca 2011 Witam was raz jeszcze, mam nowy problem z Javą. Postanowiłem napisać program obsługujący bazę danych. Oto kod: BibliotekaAboutBox.java /* * BibliotekaAboutBox.java */ package biblioteka; import org.jdesktop.application.Action; public class BibliotekaAboutBox extends javax.swing.JDialog { public BibliotekaAboutBox(java.awt.Frame parent) { super(parent); initComponents(); getRootPane().setDefaultButton(closeButton); } @Action public void closeAboutBox() { dispose(); } /** 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. */ // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); javax.swing.JLabel appTitleLabel = new javax.swing.JLabel(); javax.swing.JLabel appVersionLabel = new javax.swing.JLabel(); javax.swing.JLabel versionLabel = new javax.swing.JLabel(); javax.swing.JLabel vendorLabel = new javax.swing.JLabel(); javax.swing.JLabel appVendorLabel = new javax.swing.JLabel(); javax.swing.JLabel appDescLabel = new javax.swing.JLabel(); closeButton = new javax.swing.JButton(); jPanel1.setName("jPanel1"); // NOI18N javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 100, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 100, Short.MAX_VALUE) ); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(biblioteka.BibliotekaApp.class).getContext().getResourceMap(BibliotekaAboutBox.class); setTitle(resourceMap.getString("title")); // NOI18N setBackground(resourceMap.getColor("aboutBox.background")); // NOI18N setForeground(resourceMap.getColor("aboutBox.foreground")); // NOI18N setIconImages(null); setModal(true); setName("aboutBox"); // NOI18N setResizable(false); jPanel2.setBackground(resourceMap.getColor("jPanel2.background")); // NOI18N jPanel2.setName("jPanel2"); // NOI18N appTitleLabel.setFont(appTitleLabel.getFont().deriveFont(appTitleLabel.getFont().getStyle() | java.awt.Font.BOLD, appTitleLabel.getFont().getSize()+4)); appTitleLabel.setText(resourceMap.getString("Application.title")); // NOI18N appTitleLabel.setName("appTitleLabel"); // NOI18N appVersionLabel.setText(resourceMap.getString("Application.version")); // NOI18N appVersionLabel.setName("appVersionLabel"); // NOI18N versionLabel.setFont(versionLabel.getFont().deriveFont(versionLabel.getFont().getStyle() | java.awt.Font.BOLD)); versionLabel.setText(resourceMap.getString("versionLabel.text")); // NOI18N versionLabel.setName("versionLabel"); // NOI18N vendorLabel.setFont(vendorLabel.getFont().deriveFont(vendorLabel.getFont().getStyle() | java.awt.Font.BOLD)); vendorLabel.setText(resourceMap.getString("vendorLabel.text")); // NOI18N vendorLabel.setName("vendorLabel"); // NOI18N appVendorLabel.setText(resourceMap.getString("Application.vendor")); // NOI18N appVendorLabel.setName("appVendorLabel"); // NOI18N appDescLabel.setText(resourceMap.getString("appDescLabel.text")); // NOI18N appDescLabel.setName("appDescLabel"); // NOI18N javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(biblioteka.BibliotekaApp.class).getContext().getActionMap(BibliotekaAboutBox.class, this); closeButton.setAction(actionMap.get("closeAboutBox")); // NOI18N closeButton.setText(resourceMap.getString("closeButton.text")); // NOI18N closeButton.setName("closeButton"); // NOI18N javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGap(51, 51, 51) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(appTitleLabel) .addComponent(appDescLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE) .addGroup(jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(versionLabel) .addComponent(vendorLabel)) .addGap(41, 41, 41) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(appVersionLabel) .addComponent(appVendorLabel)) .addGap(9, 9, 9))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 196, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(closeButton) .addGap(29, 29, 29))) .addGap(105, 105, 105)) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addGap(28, 28, 28) .addComponent(appTitleLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE) .addComponent(appDescLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(versionLabel) .addComponent(appVersionLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(vendorLabel) .addComponent(appVendorLabel)) .addGap(18, 18, 18) .addComponent(closeButton) .addGap(20, 20, 20)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); }// </editor-fold> // Variables declaration - do not modify private javax.swing.JButton closeButton; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; // End of variables declaration } BibliotekaView.java /* * BibliotekaView.java */ package biblioteka; import org.jdesktop.application.Action; import org.jdesktop.application.ResourceMap; import org.jdesktop.application.SingleFrameApplication; import org.jdesktop.application.FrameView; import org.jdesktop.application.TaskMonitor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; import javax.swing.Icon; import javax.swing.JDialog; import javax.swing.JFrame; /** * The application's main frame. */ public class BibliotekaView extends FrameView { public BibliotekaView(SingleFrameApplication app) { super(app); initComponents(); // status bar initialization - message timeout, idle icon and busy animation, etc ResourceMap resourceMap = getResourceMap(); int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout"); messageTimer = new Timer(messageTimeout, new ActionListener() { public void actionPerformed(ActionEvent e) { statusMessageLabel.setText(""); } }); messageTimer.setRepeats(false); int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate"); for (int i = 0; i < busyIcons.length; i++) { busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]"); } busyIconTimer = new Timer(busyAnimationRate, new ActionListener() { public void actionPerformed(ActionEvent e) { busyIconIndex = (busyIconIndex + 1) % busyIcons.length; statusAnimationLabel.setIcon(busyIcons[busyIconIndex]); } }); idleIcon = resourceMap.getIcon("StatusBar.idleIcon"); statusAnimationLabel.setIcon(idleIcon); // connecting action tasks to status bar via TaskMonitor TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext()); taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { String propertyName = evt.getPropertyName(); if ("started".equals(propertyName)) { if (!busyIconTimer.isRunning()) { statusAnimationLabel.setIcon(busyIcons[0]); busyIconIndex = 0; busyIconTimer.start(); } } else if ("done".equals(propertyName)) { busyIconTimer.stop(); statusAnimationLabel.setIcon(idleIcon); } else if ("message".equals(propertyName)) { String text = (String)(evt.getNewValue()); statusMessageLabel.setText((text == null) ? "" : text); messageTimer.restart(); } else if ("progress".equals(propertyName)) { int value = (Integer)(evt.getNewValue()); } } }); } @Action public void showAboutBox() { if (aboutBox == null) { JFrame mainFrame = BibliotekaApp.getApplication().getMainFrame(); aboutBox = new BibliotekaAboutBox(mainFrame); aboutBox.setLocationRelativeTo(mainFrame); } BibliotekaApp.getApplication().show(aboutBox); } public void showDodajBook() { if (DodajBook == null) { JFrame mainFrame = BibliotekaApp.getApplication().getMainFrame(); DodajBook = new Dodaj(mainFrame); DodajBook.setLocationRelativeTo(mainFrame); } BibliotekaApp.getApplication().show(DodajBook); } /** 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() { mainPanel = new javax.swing.JPanel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); menuBar = new javax.swing.JMenuBar(); javax.swing.JMenu fileMenu = new javax.swing.JMenu(); javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem(); javax.swing.JMenu helpMenu = new javax.swing.JMenu(); javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem(); statusPanel = new javax.swing.JPanel(); javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator(); statusMessageLabel = new javax.swing.JLabel(); statusAnimationLabel = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); mainPanel.setName("mainPanel"); // NOI18N org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(biblioteka.BibliotekaApp.class).getContext().getResourceMap(BibliotekaView.class); jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N jButton1.setName("jButton1"); // NOI18N jButton1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton1MouseClicked(evt); } }); jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N jButton2.setName("jButton2"); // NOI18N jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N jButton3.setName("jButton3"); // NOI18N javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(mainPanelLayout.createSequentialGroup() .addGap(42, 42, 42) .addComponent(jButton1) .addContainerGap(278, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() .addContainerGap(274, Short.MAX_VALUE) .addComponent(jButton3) .addGap(24, 24, 24)) .addGroup(mainPanelLayout.createSequentialGroup() .addGap(153, 153, 153) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(162, Short.MAX_VALUE)) ); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(mainPanelLayout.createSequentialGroup() .addGap(60, 60, 60) .addComponent(jButton1) .addGap(33, 33, 33) .addComponent(jButton2) .addGap(33, 33, 33) .addComponent(jButton3) .addContainerGap(46, Short.MAX_VALUE)) ); menuBar.setName("menuBar"); // NOI18N fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N fileMenu.setName("fileMenu"); // NOI18N javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(biblioteka.BibliotekaApp.class).getContext().getActionMap(BibliotekaView.class, this); exitMenuItem.setAction(actionMap.get("quit")); // NOI18N exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N exitMenuItem.setName("exitMenuItem"); // NOI18N fileMenu.add(exitMenuItem); menuBar.add(fileMenu); helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N helpMenu.setName("helpMenu"); // NOI18N aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N aboutMenuItem.setText(resourceMap.getString("aboutMenuItem.text")); // NOI18N aboutMenuItem.setName("aboutMenuItem"); // NOI18N helpMenu.add(aboutMenuItem); menuBar.add(helpMenu); statusPanel.setName("statusPanel"); // NOI18N statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N statusMessageLabel.setName("statusMessageLabel"); // NOI18N statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N jLabel1.setName("jLabel1"); // NOI18N jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N jLabel2.setName("jLabel2"); // NOI18N jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N jLabel3.setName("jLabel3"); // NOI18N jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N jLabel4.setName("jLabel4"); // NOI18N javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel); statusPanel.setLayout(statusPanelLayout); statusPanelLayout.setHorizontalGroup( statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(statusPanelLayout.createSequentialGroup() .addContainerGap() .addComponent(statusMessageLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel1) .addGap(10, 10, 10) .addComponent(jLabel2) .addGap(37, 37, 37) .addComponent(jLabel3) .addGap(18, 18, 18) .addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 114, Short.MAX_VALUE) .addComponent(statusAnimationLabel) .addContainerGap()) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup() .addGap(118, 118, 118) .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)) ); statusPanelLayout.setVerticalGroup( statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(statusPanelLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup() .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(statusMessageLabel) .addComponent(statusAnimationLabel)) .addGap(3, 3, 3)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jLabel2) .addComponent(jLabel3) .addComponent(jLabel4)))) ); setComponent(mainPanel); setMenuBar(menuBar); setStatusBar(statusPanel); }// </editor-fold> private void jButton1MouseClicked(java.awt.event.MouseEvent evt) { showDodajBook(); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JPanel mainPanel; private javax.swing.JMenuBar menuBar; private javax.swing.JLabel statusAnimationLabel; private javax.swing.JLabel statusMessageLabel; private javax.swing.JPanel statusPanel; // End of variables declaration private final Timer messageTimer; private final Timer busyIconTimer; private final Icon idleIcon; private final Icon[] busyIcons = new Icon[15]; private int busyIconIndex = 0; private JDialog aboutBox; private JDialog DodajBook; } dodaj.java /* * BibliotekaAboutBox.java */ package biblioteka; import org.jdesktop.application.Action; public class Dodaj extends javax.swing.JDialog { public Dodaj(java.awt.Frame parent) { super(parent); initComponents(); getRootPane().setDefaultButton(jButton1); } @Action public void closeAboutBox() { dispose(); } /** 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. */ // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jTextField3 = new javax.swing.JTextField(); jTextField4 = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jTextField5 = new javax.swing.JTextField(); jTextField6 = new javax.swing.JTextField(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); jTextField7 = new javax.swing.JTextField(); jTextField8 = new javax.swing.JTextField(); jTextField9 = new javax.swing.JTextField(); jLabel14 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jButton1 = new javax.swing.JButton(); jPanel1.setName("jPanel1"); // NOI18N javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 100, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 100, Short.MAX_VALUE) ); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(biblioteka.BibliotekaApp.class).getContext().getResourceMap(Dodaj.class); setTitle(resourceMap.getString("title")); // NOI18N setBackground(resourceMap.getColor("aboutBox.background")); // NOI18N setIconImages(null); setModal(true); setName("aboutBox"); // NOI18N setResizable(false); jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N jLabel1.setName("jLabel1"); // NOI18N jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N jLabel2.setName("jLabel2"); // NOI18N jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N jLabel3.setName("jLabel3"); // NOI18N jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N jTextField1.setName("jTextField1"); // NOI18N jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N jTextField2.setName("jTextField2"); // NOI18N jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N jLabel4.setName("jLabel4"); // NOI18N jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N jLabel5.setName("jLabel5"); // NOI18N jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N jLabel6.setName("jLabel6"); // NOI18N jTextField3.setText(resourceMap.getString("jTextField3.text")); // NOI18N jTextField3.setName("jTextField3"); // NOI18N jTextField4.setText(resourceMap.getString("jTextField4.text")); // NOI18N jTextField4.setName("jTextField4"); // NOI18N jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N jLabel7.setName("jLabel7"); // NOI18N jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N jLabel8.setName("jLabel8"); // NOI18N jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N jLabel9.setName("jLabel9"); // NOI18N jTextField5.setText(resourceMap.getString("jTextField5.text")); // NOI18N jTextField5.setName("jTextField5"); // NOI18N jTextField6.setText(resourceMap.getString("jTextField6.text")); // NOI18N jTextField6.setName("jTextField6"); // NOI18N jLabel10.setFont(resourceMap.getFont("jLabel10.font")); // NOI18N jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N jLabel10.setName("jLabel10"); // NOI18N jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N jLabel11.setName("jLabel11"); // NOI18N jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N jLabel12.setName("jLabel12"); // NOI18N jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N jLabel13.setName("jLabel13"); // NOI18N jTextField7.setText(resourceMap.getString("jTextField7.text")); // NOI18N jTextField7.setName("jTextField7"); // NOI18N jTextField8.setText(resourceMap.getString("jTextField8.text")); // NOI18N jTextField8.setName("jTextField8"); // NOI18N jTextField9.setText(resourceMap.getString("jTextField9.text")); // NOI18N jTextField9.setName("jTextField9"); // NOI18N jLabel14.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N jLabel14.setName("jLabel14"); // NOI18N jScrollPane1.setName("jScrollPane1"); // NOI18N jTextArea1.setColumns(20); jTextArea1.setFont(resourceMap.getFont("jTextArea1.font")); // NOI18N jTextArea1.setRows(5); jTextArea1.setName("jTextArea1"); // NOI18N jScrollPane1.setViewportView(jTextArea1); jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N jButton1.setName("jButton1"); // NOI18N jButton1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton1MouseClicked(evt); } }); 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(210, 210, 210) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel12) .addComponent(jLabel11) .addComponent(jLabel13)) .addGap(69, 69, 69) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jTextField8, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE) .addComponent(jTextField9, javax.swing.GroupLayout.Alignment.LEADING)) .addContainerGap(215, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGap(344, 344, 344) .addComponent(jLabel14) .addContainerGap(269, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(353, Short.MAX_VALUE) .addComponent(jButton1) .addGap(307, 307, 307)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 671, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(34, 34, 34) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(jLabel3)) .addGap(65, 65, 65) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField2) .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)) .addGap(46, 46, 46) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5) .addComponent(jLabel6)) .addGap(70, 70, 70) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField4) .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE))) .addComponent(jLabel10)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)) .addGroup(layout.createSequentialGroup() .addGap(90, 90, 90) .addComponent(jLabel1) .addGap(216, 216, 216) .addComponent(jLabel4))) .addGap(30, 30, 30) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(37, 37, 37) .addComponent(jLabel7) .addGap(134, 134, 134)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel8) .addComponent(jLabel9)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField6) .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)))))) .addGap(25, 25, 25)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(21, 21, 21) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jLabel4)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5) .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(jLabel3) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup() .addComponent(jLabel7) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8) .addComponent(jTextField5, 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(jLabel9) .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGap(51, 51, 51) .addComponent(jLabel10) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel11) .addComponent(jTextField7, 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(jLabel12) .addComponent(jTextField8, 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(jLabel13) .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(jLabel14) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1) .addContainerGap(14, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void jButton1MouseClicked(java.awt.event.MouseEvent evt) { BibliotekaApp.ksiazki[BibliotekaApp.iksiazki][0]=jTextField1.getText(); BibliotekaApp.ksiazki[BibliotekaApp.iksiazki][0]=jTextField2.getText(); BibliotekaApp.ksiazki[BibliotekaApp.iksiazki][0]=jTextField3.getText(); BibliotekaApp.ksiazki[BibliotekaApp.iksiazki][0]=jTextField4.getText(); BibliotekaApp.ksiazki[BibliotekaApp.iksiazki][0]=jTextField5.getText(); BibliotekaApp.ksiazki[BibliotekaApp.iksiazki][0]=jTextField6.getText(); BibliotekaApp.ksiazki[BibliotekaApp.iksiazki][0]=jTextField7.getText(); BibliotekaApp.ksiazki[BibliotekaApp.iksiazki][0]=jTextField8.getText(); BibliotekaApp.ksiazki[BibliotekaApp.iksiazki][0]=jTextField9.getText(); BibliotekaApp.ksiazki[BibliotekaApp.iksiazki][0]=jTextArea1.getText(); BibliotekaApp.zapis();//jak wywalę tą linijkę, to błędów nie ma, ale nie o to przecież chodzi. //closeAboutBox(); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; private javax.swing.JTextField jTextField5; private javax.swing.JTextField jTextField6; private javax.swing.JTextField jTextField7; private javax.swing.JTextField jTextField8; private javax.swing.JTextField jTextField9; // End of variables declaration } <b>BibliotekaApp.java</b> /* * BibliotekaApp.java */ package biblioteka; import org.jdesktop.application.Application; import org.jdesktop.application.SingleFrameApplication; import java.io.BufferedWriter; import java.io.IOException; import java.io.FileWriter; /** * The main class of the application. */ public class BibliotekaApp extends SingleFrameApplication { /** * At startup create and show the main frame of the application. */ public static String[][] ksiazki=new String[1000000][11]; public static String[][] uczniowie=new String[1000000][5]; public static int iksiazki, iuczniowie=1; static FileWriter fw=null; static FileWriter fw1=null; public static void zapis() { try { fw=new FileWriter("plik.txt"); fw1=new FileWriter("plik1.txt"); } catch(IOException e) { e.printStackTrace(); } BufferedWriter writer=new BufferedWriter(fw); BufferedWriter writer1=new BufferedWriter(fw1); try { for (int i = 0; i < iksiazki; i++) { writer.write("============================="); writer.newLine(); for (int j=0;j<ksiazki[i].length;j++) { switch (j) { case 0: writer.write("Imie: "); writer.newLine(); break; case 1: writer.write("Nazwisko: "); writer.newLine(); break; case 2: writer.write("Tytół: "); writer.newLine(); break; case 3: writer.write("Podtytół: "); writer.newLine(); break; case 4: writer.write("ISBN: "); writer.newLine(); break; case 5: writer.write("Numer biblioteczny: "); writer.newLine(); break; case 6: writer.write("Nazwa wydawnictwa: "); writer.newLine(); break; case 7: writer.write("Data wydania: "); writer.newLine(); break; case 8: writer.write("Miejsce wydania: "); writer.newLine(); break; case 9: writer.write("Informacje dodatkowe: "); writer.newLine(); break; case 10: writer.write("Wypożyczył: "); writer.newLine(); break; } writer.write(ksiazki[i][j]); writer.newLine(); } } for (int i = 0; i < iuczniowie; i++) { for (int j=0;j<uczniowie[i].length;j++) { writer1.write(uczniowie[i][j]); writer1.newLine(); } } } catch (IOException e) { e.printStackTrace(); } try { writer.close(); fw.close(); } catch (IOException e) { e.printStackTrace(); } } @Override protected void startup() { show(new BibliotekaView(this)); } /** * This method is to initialize the specified window by injecting resources. * Windows shown in our application come fully initialized from the GUI * builder, so this additional configuration is not needed. */ @Override protected void configureWindow(java.awt.Window root) { } /** * A convenient static getter for the application instance. * @return the instance of BibliotekaApp */ public static BibliotekaApp getApplication() { return Application.getInstance(BibliotekaApp.class); } /** * Main method launching the application. */ public static void main(String[] args) { launch(BibliotekaApp.class, args); } } Kiedy wywołuję funkcję zapis, wywala błędy: Exception occurred during event dispatching: java.lang.NullPointerException at java.io.Writer.write(Writer.java:140) at biblioteka.BibliotekaApp.zapis(BibliotekaApp.java:107) at biblioteka.Dodaj.jButton1MouseClicked(Dodaj.java:314) at biblioteka.Dodaj.access$000(Dodaj.java:11) at biblioteka.Dodaj$1.mouseClicked(Dodaj.java:167) at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253) at java.awt.Component.processMouseEvent(Component.java:6291) at javax.swing.JComponent.processMouseEvent(JComponent.java:3267) at java.awt.Component.processEvent(Component.java:6053) at java.awt.Container.processEvent(Container.java:2041) at java.awt.Component.dispatchEventImpl(Component.java:4651) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Component.dispatchEvent(Component.java:4481) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168) at java.awt.Container.dispatchEventImpl(Container.java:2085) at java.awt.Window.dispatchEventImpl(Window.java:2478) at java.awt.Component.dispatchEvent(Component.java:4481) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643) at java.awt.EventQueue.access$000(EventQueue.java:84) at java.awt.EventQueue$1.run(EventQueue.java:602) at java.awt.EventQueue$1.run(EventQueue.java:600) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98) at java.awt.EventQueue$2.run(EventQueue.java:616) at java.awt.EventQueue$2.run(EventQueue.java:614) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.awt.EventQueue.dispatchEvent(EventQueue.java:613) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178) at java.awt.Dialog$1.run(Dialog.java:1046) at java.awt.Dialog$3.run(Dialog.java:1098) at java.security.AccessController.doPrivileged(Native Method) at java.awt.Dialog.show(Dialog.java:1096) at java.awt.Component.show(Component.java:1584) at java.awt.Component.setVisible(Component.java:1536) at java.awt.Window.setVisible(Window.java:842) at java.awt.Dialog.setVisible(Dialog.java:986) at org.jdesktop.application.SingleFrameApplication.show(SingleFrameApplication.java:296) at biblioteka.BibliotekaView.showDodajBook(BibliotekaView.java:100) at biblioteka.BibliotekaView.jButton1MouseClicked(BibliotekaView.java:272) at biblioteka.BibliotekaView.access$700(BibliotekaView.java:22) at biblioteka.BibliotekaView$4.mouseClicked(BibliotekaView.java:139) at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253) at java.awt.Component.processMouseEvent(Component.java:6291) at javax.swing.JComponent.processMouseEvent(JComponent.java:3267) at java.awt.Component.processEvent(Component.java:6053) at java.awt.Container.processEvent(Container.java:2041) at java.awt.Component.dispatchEventImpl(Component.java:4651) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Component.dispatchEvent(Component.java:4481) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168) at java.awt.Container.dispatchEventImpl(Container.java:2085) at java.awt.Window.dispatchEventImpl(Window.java:2478) at java.awt.Component.dispatchEvent(Component.java:4481) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643) at java.awt.EventQueue.access$000(EventQueue.java:84) at java.awt.EventQueue$1.run(EventQueue.java:602) at java.awt.EventQueue$1.run(EventQueue.java:600) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98) at java.awt.EventQueue$2.run(EventQueue.java:616) at java.awt.EventQueue$2.run(EventQueue.java:614) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.awt.EventQueue.dispatchEvent(EventQueue.java:613) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) Bardzo to dziwne, gdyż w tym samym miejscu wywoływałem funkcję write, tworzyłem obiekty fileWriter itd i nie było problemu. Jak to naprawić? E: I dlaczego występują te błędy? Jak unikać ich w przyszłości. E2: Pliki się tworzą, ale puste. Odnośnik do komentarza Udostępnij na innych stronach Więcej opcji udostępniania...
R.o.b Opublikowano 5 Lipca 2011 Udostępnij Opublikowano 5 Lipca 2011 Trochę dużo tego kodu. Zacznijmy od początku, czy zrobiłeś plik z bazą. Nie jestem zaawansowanymprogramistą w Javie, ale wydaje mi się, że bazy danych nie da się zapisać FileWriterem. Napisz ten problem na 4programmers, ja z problemami zgłaszam się tam, bo na tym forum jest mało javowców Odnośnik do komentarza Udostępnij na innych stronach Więcej opcji udostępniania...
Rekomendowane odpowiedzi
Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto
Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.
Zarejestruj nowe konto
Załóż nowe konto. To bardzo proste!
Zarejestruj sięZaloguj się
Posiadasz już konto? Zaloguj się poniżej.
Zaloguj się