The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Can anyone find the error in this Code..?

Posted by Avin Sinanan on November 28, 2001 at 4:28 AM

Ok here is the thing.. You will need two gif files called
HLPCD.gif and pic2.gif

Bascially when you load the program you can add pictures to the screen and move it around. When you click on the add buttons if the pictures doesn't appear move the splitpane bar from side to side a bit and the pictures will appear. (You will know what am talking about when you load the program).
No when you add one BTS and one Mobile to the screen you can doublle click each picture and a TextField appears( the double clicking gives some trouble.. the picture tends to move when you try to double click it.. but be patient please.. when you double click on each one and the tect field appears you can give the picture a name...and when you do and press enter the name appears within the pic.

Ok but my problem is.. if you look at the code when the names of the both pictures are the same a messsage in the DOS window is suppose to print " They are Connented"
However the program is not doing this. When the names of the pics are the same and diffrent it prints the Else messsage which is "They are NOT NOT connected"

Can someone tell me what the wrror is? I know its a big program.. but give ita look if you have the time.. i have spent hours and hours on this... any help would be appreciated.. thanks....


code

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;


class AvinCommunicate
{

public static void main(String[] args)
{

JFrame workBench = new JFrame("Work Bench") ;
final JPanel pane1 = new JPanel();
final JPanel pane2= new JPanel();

//To pane1 we have to add the icon buttons.
//Adding the BST icon/button

BaseStationIconAdder bts = new BaseStationIconAdder();
MobileStationIconAdder msia = new MobileStationIconAdder();


final JButton baseStationAdderButton = bts.baseStationMethod();
final JButton mobileStationAdderButton = msia.mobileStationMethod();
pane1.add(baseStationAdderButton);
pane1.add(mobileStationAdderButton);

//Adding Action Events on ToolBar buttons
//--------------------------------------------------------------------
baseStationAdderButton.setMnemonic(KeyEvent.VK_I);
baseStationAdderButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){

BaseStationIconClass baseStationIconClass = new BaseStationIconClass();
final JButton baseStationIconButton = baseStationIconClass.baseStationIconMethod();
pane2.add(baseStationIconButton);




//------------------------------------------------------------------

//Now what happens when we double click the actual BTS icon
//a parameter box appears.

baseStationIconButton.addMouseListener(new MouseListener()
{
public void mousePressed(MouseEvent e)
{
System.out.println("You have Pressed " +"\n");
}
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2)
{
System.out.println("Help am In");
BaseStationParameterClass bSPC = new BaseStationParameterClass();
bSPC.baseStationParameterMethod(baseStationIconButton);

}

}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
});



}
});


mobileStationAdderButton.setMnemonic(KeyEvent.VK_L);
mobileStationAdderButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent f){

MobileStationIconClass mobileStationIconClass = new MobileStationIconClass();
final JButton mobileStationIconButton = mobileStationIconClass.mobileStationIconMethod();
pane2.add(mobileStationIconButton);


mobileStationIconButton.addMouseListener(new MouseListener()
{
public void mousePressed(MouseEvent e)
{
System.out.println("You have Pressed " +"\n");
}
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2)
{

MobileStationParameterClass mSPC = new MobileStationParameterClass();
mSPC.mobileStationParameterMethod(mobileStationIconButton);

}

}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}

});
}
});



JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,pane1, pane2);
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(150);

//Provide minimum sizes for the two components in the split pane
Dimension minimumSize = new Dimension(100, 50);
pane1.setMinimumSize(minimumSize);
pane2.setMinimumSize(minimumSize);
splitPane.setPreferredSize(new Dimension(400, 200));

workBench.getContentPane().add(splitPane);

//Setting some common parameters for workDesk

workBench.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
workBench.setSize(500,500);
workBench.pack();
workBench.setVisible(true) ;





}

}

class BaseStationIconAdder
{
public JButton baseStationMethod()
{
final JButton btsButton = new JButton("Add BTS");
return btsButton ;
}
}


class MobileStationIconAdder
{
public JButton mobileStationMethod()
{
final JButton msiaButton = new JButton("Add Mobile");
return msiaButton ;
}
}

//---------------------------------------------------------------------
class BaseStationIconClass
{
public JButton baseStationIconMethod()
{
JButton baseStationIcon = new JButton("1",new ImageIcon("HLPCD.gif"));
baseStationIcon.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent me) {
me.getComponent().setLocation(me.getComponent().getX() + me.getX(),
me.getComponent().getY() + me.getY());

}
});

return baseStationIcon ;
}
}



class MobileStationIconClass
{
public JButton mobileStationIconMethod()
{
JButton mobileStationIcon = new JButton("1",new ImageIcon("pic2.gif"));
mobileStationIcon.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent mee) {
mee.getComponent().setLocation(mee.getComponent().getX() + mee.getX(),
mee.getComponent().getY() + mee.getY());

}
});

return mobileStationIcon ;
}
}

//--------------------------------------------------------------------

class BaseStationParameterClass
{

public void baseStationParameterMethod(JButton baseStationIconButton)
{
JFrame baseStationParameterFrame = new JFrame("Base Transceiver Parameter Window");
JPanel BTSPane = new JPanel();
JTextField nameField = new JTextField("", 20);
nameField.addActionListener(new TextFieldListener(nameField,baseStationIconButton));



BTSPane.add(nameField);
baseStationParameterFrame.getContentPane().add(BTSPane);
baseStationParameterFrame.setSize(300,300);
baseStationParameterFrame.pack();
baseStationParameterFrame.setVisible(true) ;


}
}

class TextFieldListener implements ActionListener
{
JTextField fieldSwitch ;
JButton buffButtonTwo ;


TextFieldListener(JTextField nameField , JButton baseStationIconButton )
{

fieldSwitch = nameField ;
buffButtonTwo = baseStationIconButton ;
}

public void actionPerformed(ActionEvent evt)
{

JTextField inputField = (JTextField)evt.getSource();
Global.typedText = fieldSwitch.getText();
buffButtonTwo.setText(Global.typedText);



}

}

class MobileStationParameterClass
{

public void mobileStationParameterMethod(JButton mobileStationIconButton)
{
JFrame mobileStationParameterFrame = new JFrame("Mobile Station Parameter Window");
JPanel MOBPane = new JPanel();
//baseStationParameterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JTextField registerField = new JTextField("", 20);
registerField.addActionListener(new TextFieldListener1(registerField,mobileStationIconButton));



MOBPane.add(registerField);
mobileStationParameterFrame.getContentPane().add(MOBPane);
mobileStationParameterFrame.setSize(300,300);
mobileStationParameterFrame.pack();
mobileStationParameterFrame.setVisible(true) ;


}
}

class TextFieldListener1 implements ActionListener
{
JTextField regFieldSwitch ;
JButton buffButtonTwoAgain ;


TextFieldListener1(JTextField registerField , JButton mobileStationIconButton )
{

regFieldSwitch = registerField ;
buffButtonTwoAgain = mobileStationIconButton ;
}

public void actionPerformed(ActionEvent evt)
{

JTextField inputField = (JTextField)evt.getSource();
Global.regText = regFieldSwitch.getText();
buffButtonTwoAgain.setText(Global.regText);

if(Global.regText == Global.typedText)

{
System.out.println("They are connected");
}
else
{
System.out.println("They are NOT NOT connected");
}

}
}

class Global
{
public static String regText ;
public static String typedText;

}





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us