Results 1 to 2 of 2
Thread: Need a bit of help
- 01-17-2011, 02:10 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 1
- Rep Power
- 0
Need a bit of help
Java Code:package IrcCleint; import javax.swing.*; import java.awt.*; /** * * @author Jonathan */ public class IrcClientUI extends javax.swing.JFrame { /** Creates new form IrcClientUI */ public IrcClientUI() { 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() { serverTabs = new javax.swing.JTabbedPane(); jMenuBar1 = new javax.swing.JMenuBar(); fileMenu = new javax.swing.JMenu(); newServer = new javax.swing.JMenuItem(); jSeparator1 = new javax.swing.JPopupMenu.Separator(); exitProgram = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); serverTabs.setEnabled(false); fileMenu.setText("File"); fileMenu.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { fileMenuActionPerformed(evt); } }); newServer.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.ALT_MASK)); newServer.setText("New Server"); newServer.setToolTipText("Specify a new irc server to connect to."); newServer.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { newServerActionPerformed(evt); } }); fileMenu.add(newServer); fileMenu.add(jSeparator1); exitProgram.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.ALT_MASK)); exitProgram.setText("Exit"); exitProgram.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitProgramActionPerformed(evt); } }); fileMenu.add(exitProgram); jMenuBar1.add(fileMenu); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(serverTabs, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 906, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(serverTabs, javax.swing.GroupLayout.DEFAULT_SIZE, 444, Short.MAX_VALUE) ); pack(); }// </editor-fold> private void exitProgramActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0); } private void fileMenuActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } [COLOR="Red"]private void newServerActionPerformed(java.awt.event.ActionEvent evt) { new IrcInputUI(this).setVisible(true); }[/COLOR] public void getOptionsInput(String server, String username, String tabName, String channel) { serverTabs.addTab(tabName, panel1); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new IrcClientUI().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JMenuItem exitProgram; private javax.swing.JMenu fileMenu; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JPopupMenu.Separator jSeparator1; private javax.swing.JMenuItem newServer; private javax.swing.JTabbedPane serverTabs;Java Code:package IrcCleint; import javax.swing.*; import java.awt.*; /** * * @author Jonathan */ public class IrcInputUI extends JDialog { /** Creates new form IrcInputUI */ public IrcInputUI(JFrame parent) { super(parent,true); initComponents(); Rectangle parentBounds = parent.getBounds(); Dimension size = getSize(); //Center in the parent int x = Math.max(0, parentBounds.x + (parentBounds.width - size.width) / 2); int y = Math.max(0, parentBounds.y + (parentBounds.height - size.height) / 2); this.setLocation(new Point(x, y)); } /** 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() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); serverInput = new javax.swing.JTextField(); portInput = new javax.swing.JTextField(); usernameInput = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); channelInput = new javax.swing.JTextField(); connectButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Server Options")); jLabel1.setText("Server"); jLabel2.setText("Port"); jLabel3.setText("User Name"); serverInput.setText("irc.tribalwar.com"); portInput.setText("6667"); usernameInput.setText("UnoBot2"); jLabel4.setText("Channel"); channelInput.setText("#unobot"); 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(jLabel1) .addGap(38, 38, 38) .addComponent(serverInput, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel2) .addGap(50, 50, 50) .addComponent(portInput, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3) .addComponent(jLabel4)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(channelInput, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE) .addComponent(usernameInput, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)))) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(serverInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(portInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(usernameInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(channelInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); connectButton.setText("Connect"); connectButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { connectButtonActionPerformed(evt); } }); cancelButton.setText("Cancel"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(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() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(connectButton) .addGap(18, 18, 18) .addComponent(cancelButton) .addGap(49, 49, 49)) .addGroup(layout.createSequentialGroup() .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cancelButton) .addComponent(connectButton)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); getAccessibleContext().setAccessibleParent(this); pack(); }// </editor-fold> [COLOR="BLUE"]private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) { String server = serverInput.getText() + ":" + portInput.getText(); String username = usernameInput.getText(); String channel; int index = serverInput.getText().indexOf('.') + 1; int index2 = serverInput.getText().lastIndexOf('.'); String tabName = serverInput.getText().substring(index, index2); String firstLetter = tabName.substring(0,1); String remainder = tabName.substring(1); tabName = firstLetter.toUpperCase() + remainder.toLowerCase(); if (!channelInput.getText().startsWith("#")) { channel = "#" + channelInput.getText(); } else { channel = channelInput.getText(); }[/COLOR] this.setVisible(false); } private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); } /** * @param args the command line arguments */ // Variables declaration - do not modify private javax.swing.JButton cancelButton; private javax.swing.JTextField channelInput; private javax.swing.JButton connectButton; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JPanel jPanel1; private javax.swing.JTextField portInput; private javax.swing.JTextField serverInput; private javax.swing.JTextField usernameInput;
Okay so I have a basic outline for a GUI I'm just working on for fun. Its just going to be a super simple irc client, that I'm going to use to run some game bots that I programmed in the past.
My problem is, when I click the new server menu item (event action that is highlighted in RED), it creates my options window correctly. However, for the life of me I can't figure out how to get those options (the method highlighted in BLUE) back to my original class so I can continue working with them. The intention is to send my options back to the main window whenever I hit the connect JButton.
Any help is appreciated. I'm sure theres just something simple I am missing because of my extreme lack of programming knowledge, but I just cant figure it out :(Last edited by Keirathi; 01-17-2011 at 02:33 AM.
- 01-17-2011, 06:54 AM #2


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks