Total members 11895 |It is currently Sun Dec 22, 2024 2:28 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Code:
//Import packages
    
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
//main class
public class FirstGUI {
    
//Declare variables
            
static JFrame frame1;
            static 
Container pane;
            static 
JButton btnConnectbtnDisconnect;
            static 
JLabel lblServerlblUsernamelblPasswordlblPort;
            static 
JTextField txtServertxtUsernametxtPasswordtxtPort;
            static 
Insets insets;}
    public static 
void main(String[] args) {
         
//Create the frame
                    
frame1 = new JFrame ("Sample GUI Application");
                
//Set its size to 800x200 pixels
                    
frame1.setSize (800,200);
                    
//Prepare panel
                    
pane frame1.getContentPane();
                    
insets pane.getInsets();
                    
//Apply the null layout
                    
pane.setLayout (null);
    
btnConnect = new JButton ("Connect");
        
btnDisconnect = new JButton ("Disconnect");
        
lblServer = new JLabel ("Remote host:");
        
lblUsername = new JLabel ("Username:");
        
lblPassword = new JLabel ("Password:");
        
lblPort = new JLabel ("Port #:");
        
txtServer = new JTextField (10);
        
txtUsername = new JTextField  (10);
        
txtPassword = new JTextField  (10);
            
txtPort = new JTextField  (5);
    
pane.add (lblServer); //Add component to panel
        
lblServer.setBounds (insets.left 5insets.top 5lblServer.getPreferredSize().widthlblServer.getPreferredSize().height);
        
//Add all components to panel
            
pane.add (lblServer);
            
pane.add (lblUsername);
            
pane.add (lblPassword);
            
pane.add (lblPort);
            
pane.add (txtServer);
            
pane.add (txtUsername);
            
pane.add (txtPassword);
            
pane.add (txtPort);
            
pane.add (btnConnect);
            
pane.add (btnDisconnect);
             
            
//Place all components
            
lblServer.setBounds (insets.left 5insets.top 5lblServer.getPreferredSize().widthlblServer.getPreferredSize().height);
            
txtServer.setBounds (lblServer.getX() + lblServer.getWidth() + 5insets.top 5txtServer.getPreferredSize().widthtxtServer.getPreferredSize().height);
             
            
lblUsername.setBounds (txtServer.getX() + txtServer.getWidth() + 5insets.top 5lblUsername.getPreferredSize().widthlblUsername.getPreferredSize().height);
            
txtUsername.setBounds (lblUsername.getX() + lblUsername.getWidth() + 5insets.top 5txtUsername.getPreferredSize().widthtxtUsername.getPreferredSize().height);
             
            
lblPassword.setBounds (txtUsername.getX() + txtUsername.getWidth() + 5insets.top 5lblPassword.getPreferredSize().widthlblPassword.getPreferredSize().height);
            
txtPassword.setBounds (lblPassword.getX() + lblPassword.getWidth() + 5insets.top 5txtPassword.getPreferredSize().widthtxtPassword.getPreferredSize().height);
             
            
lblPort.setBounds (txtPassword.getX() + txtPassword.getWidth() + 5insets.top 5lblPort.getPreferredSize().widthlblPort.getPreferredSize().height);
            
txtPort.setBounds (lblPort.getX() + lblPort.getWidth() + 5insets.top 5txtPort.getPreferredSize().widthtxtPort.getPreferredSize().height);
         
            
btnConnect.setBounds (txtPort.getX() + txtPort.getWidth() + 5insets.top 5btnConnect.getPreferredSize().widthbtnConnect.getPreferredSize().height);
         
            
//Place disconnect button (start a new line!)
            
btnDisconnect.setBounds (insets.left 15lblServer.getY() + lblServer.getHeight() + 5btnDisconnect.getPreferredSize().widthbtnDisconnect.getPreferredSize().height);
            
frame1.setVisible (true);
            
//Set Look and Feel
            
try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
                catch (
ClassNotFoundException e) {}
                catch (
InstantiationException e) {}
                catch (
IllegalAccessException e) {}
                catch (
UnsupportedLookAndFeelException e) {}
            
btnConnect.addActionListener(new btnConnectAction()); //Register action
            
public static class btnConnectAction implements ActionListener{
                public static class 
btnConnectAction implements ActionListener{
                            public 
void actionPerformed (ActionEvent e){
                            
System.out.println("You entered "+txtUsername.getText());
            }
    }

I did not understand whats the problem with this code every time it says"The type btnConnectAction must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)"or"The nested type btnConnectAction cannot hide an enclosing type"




Author:
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Button action listener should implement abstract method
 What is an abstract method     -  
 Text Listener for events TextListener-on TextArea-TextField     -  
 Convert link and button to custom button with good style     -  
 php extends in action     -  
 is_numeric in action     -  
 php SAX parser in action     -  
 JButtons implementing an Action     -  
 relationship an event-listener interface & event handler     -  
 how to implement an interface     -  
 How to implement HttpSessionListener in JSP     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com