Java tutorial
/* * 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 radnet; import java.awt.Desktop; import javax.swing.DefaultListModel; import javax.swing.JList; import radnet.conf.ConfigurationContainer; import radnet.conf.TwitterInformation; import twitter4j.Twitter; import twitter4j.TwitterException; import twitter4j.TwitterFactory; import twitter4j.auth.AccessToken; import twitter4j.auth.RequestToken; /** * * @author Shoshanna */ public class ConfigWindow extends javax.swing.JDialog { private AccessToken accessToken; private Twitter twitter; private RequestToken requestToken; /** * Creates new form ConfigWindow */ public ConfigWindow(java.awt.Frame parent, boolean modal) { super(parent, modal); 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() { jTabbedPane1 = new javax.swing.JTabbedPane(); jPanel1 = new javax.swing.JPanel(); chkboxRecursiveScan = new javax.swing.JCheckBox(); chkboxDownloadRoms = new javax.swing.JCheckBox(); chkboxSkipHidden = new javax.swing.JCheckBox(); jPanel7 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); listRomDirectories = new javax.swing.JList(); btnAddNewDirectory = new javax.swing.JButton(); btnRemoveSelectedDirectory = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); jPanel5 = new javax.swing.JPanel(); jLabel3 = new javax.swing.JLabel(); twit_submit = new javax.swing.JButton(); twit_password = new javax.swing.JTextField(); jPanel6 = new javax.swing.JPanel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jTextField2 = new javax.swing.JTextField(); jPasswordField2 = new javax.swing.JPasswordField(); jButton6 = new javax.swing.JButton(); chkboxAllowPosting = new javax.swing.JCheckBox(); chkboxAllowSelfPosting = new javax.swing.JCheckBox(); jPanel4 = new javax.swing.JPanel(); btnCloseOkay = new javax.swing.JButton(); btnHelp = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setAlwaysOnTop(true); setMaximumSize(new java.awt.Dimension(450, 500)); setMinimumSize(new java.awt.Dimension(450, 500)); setPreferredSize(new java.awt.Dimension(450, 500)); setResizable(false); addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(java.awt.event.WindowEvent evt) { formWindowOpened(evt); } }); chkboxRecursiveScan.setText("Recursive audit on RadNet startup"); chkboxDownloadRoms.setText("Automatically download missing roms (when applicable)"); chkboxSkipHidden.setText("Skip hidden files"); jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Directory Locations")); jLabel1.setText("Rom Location"); jScrollPane1.setViewportView(listRomDirectories); btnAddNewDirectory.setText("Add New"); btnRemoveSelectedDirectory.setText("Remove Selected"); javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); jPanel7.setLayout(jPanel7Layout); jPanel7Layout.setHorizontalGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup().addContainerGap().addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent( jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(btnRemoveSelectedDirectory) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnAddNewDirectory))) .addContainerGap())); jPanel7Layout.setVerticalGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnAddNewDirectory).addComponent(btnRemoveSelectedDirectory)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) .addGroup( jPanel1Layout.createSequentialGroup().addGap(10, 10, 10) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(chkboxDownloadRoms).addComponent(chkboxRecursiveScan) .addComponent(chkboxSkipHidden)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(chkboxRecursiveScan) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(chkboxDownloadRoms) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(chkboxSkipHidden).addContainerGap(180, Short.MAX_VALUE))); jTabbedPane1.addTab("Directories", jPanel1); jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Twitter")); jLabel3.setText("Pin"); twit_submit.setText("Verify Account"); twit_submit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { twit_submitActionPerformed(evt); } }); twit_password.setEnabled(false); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout.setHorizontalGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(jPanel5Layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(twit_submit)) .addGroup(jPanel5Layout.createSequentialGroup().addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(twit_password))) .addContainerGap())); jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup().addGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel3) .addComponent(twit_password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(twit_submit))); jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Google")); jLabel4.setText("Username"); jLabel5.setText("Password"); jButton6.setText("Verify Account"); javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6); jPanel6.setLayout(jPanel6Layout); jPanel6Layout.setHorizontalGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup().addContainerGap().addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup() .addGroup( jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4).addComponent(jLabel5)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup( jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPasswordField2).addComponent(jTextField2))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE).addComponent(jButton6))) .addContainerGap())); jPanel6Layout.setVerticalGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4).addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5).addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton6) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); chkboxAllowPosting.setText("Allow RadNet to post games played on Twitter"); chkboxAllowPosting.setEnabled(false); chkboxAllowSelfPosting.setText("Allow RadNet to post information on Twitter (non-sensitive information.)"); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) .addGroup(jPanel2Layout.createSequentialGroup().addGap(10, 10, 10) .addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(chkboxAllowSelfPosting).addComponent(chkboxAllowPosting)) .addContainerGap(35, Short.MAX_VALUE))))); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap() .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(chkboxAllowPosting) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(chkboxAllowSelfPosting).addContainerGap(164, Short.MAX_VALUE))); jTabbedPane1.addTab("Social Networks", jPanel2); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 426, Short.MAX_VALUE)); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 421, Short.MAX_VALUE)); jTabbedPane1.addTab("About Java", jPanel4); btnCloseOkay.setText("Okay"); btnHelp.setText("Help"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTabbedPane1) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnHelp).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnCloseOkay).addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jTabbedPane1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnCloseOkay).addComponent(btnHelp)) .addContainerGap())); pack(); }// </editor-fold>//GEN-END:initComponents private void twit_submitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_twit_submitActionPerformed // TODO add your handling code here: if (twit_submit.getText() == "Verify Pin") { try { if (twit_password.getText().length() > 0) { accessToken = twitter.getOAuthAccessToken(requestToken, twit_password.getText()); // prepare for twitter data dump System.out.println(accessToken.getScreenName()); System.out.println(accessToken.getUserId()); System.out.println(accessToken.getToken()); System.out.println(accessToken.getTokenSecret()); } else { accessToken = twitter.getOAuthAccessToken(); } } catch (TwitterException te) { if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else { te.printStackTrace(); } } } else { try { twitter = TwitterFactory.getSingleton(); twitter.setOAuthConsumer("aC3MoxJN7AN23kHjVwf7Gq92H", "JA0yGiAeBZsUfafVKuNoQ8kUY9nYqr7WCR5bp4LRMAxnKRM46a"); requestToken = twitter.getOAuthRequestToken(); accessToken = null; twit_password.setEnabled(true); twit_submit.setText("Verify Pin"); Desktop.getDesktop().browse(java.net.URI.create(requestToken.getAuthenticationURL())); } catch (Exception ex) { System.out.println("An unhandled exception has occured."); } } }//GEN-LAST:event_twit_submitActionPerformed private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened // TODO add your handling code here: LoadSettings(); }//GEN-LAST:event_formWindowOpened private boolean LoadSettings() { DefaultListModel<String> listModel = new DefaultListModel<>(); listRomDirectories.setModel(listModel); for (int i = 0; i < ConfigurationContainer.romfile.size(); i++) { listModel.addElement(ConfigurationContainer.romfile.get(i)); } chkboxRecursiveScan.setSelected(ConfigurationContainer.recursive); chkboxDownloadRoms.setSelected(ConfigurationContainer.downloads); chkboxSkipHidden.setSelected(ConfigurationContainer.skiphidden); if (ConfigurationContainer.twitterEnabled) { twit_password.setText(TwitterInformation.pin); chkboxAllowPosting.setSelected(TwitterInformation.allowgames); chkboxAllowSelfPosting.setSelected(TwitterInformation.allowinfo); } return false; } private boolean SaveSettings() { return false; } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<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(ConfigWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(ConfigWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(ConfigWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(ConfigWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the dialog */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { ConfigWindow dialog = new ConfigWindow(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnAddNewDirectory; private javax.swing.JButton btnCloseOkay; private javax.swing.JButton btnHelp; private javax.swing.JButton btnRemoveSelectedDirectory; private javax.swing.JCheckBox chkboxAllowPosting; private javax.swing.JCheckBox chkboxAllowSelfPosting; private javax.swing.JCheckBox chkboxDownloadRoms; private javax.swing.JCheckBox chkboxRecursiveScan; private javax.swing.JCheckBox chkboxSkipHidden; private javax.swing.JButton jButton6; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JPanel jPanel6; private javax.swing.JPanel jPanel7; private javax.swing.JPasswordField jPasswordField2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JTextField jTextField2; private javax.swing.JList listRomDirectories; private javax.swing.JTextField twit_password; private javax.swing.JButton twit_submit; // End of variables declaration//GEN-END:variables }