Creating a Set  containing instances of another Class, which type?

Hi All,
I'm stuck trying to create a set which contains instances of another Class.
When I created my instance method, it takes an argument which is the instance of another Class.
It errors as I've used the Class as the type rather than String> or Integer.
Can someone point my in the right direction?
WebPageData wpd1 = new WebPageData("this is a sentence for a test", "www.test.com");
WebPageData wpd2 = new WebPageData("this sentence is shorter", "www.short.com");
WebPageData wpd3 = new WebPageData("this is very short", "www.very.com");
Finder f1 = new Finder();
f1.addsite(wpd1);
f1.addsite(wpd2);
f1.addsite(wpd3);
f1.searchFor("a sentence test");
Edited by: geedoubleu on Mar 16, 2008 9:03 AM

The error message is "Semantic error: line 5. Message addsite( WebPageData ) not understood by class'Finder'"
* Adds the argument of WebPageData instances to to a collection scannedSites.
public void addSite(WebPageData theWebPage)
this.scannedSites.add(theWebPage);
}

Similar Messages

  • How to create internal table storing instances of ABAP class

    Hi experts, any one knows how to create internal table storing instances of ABAP class or alternative to implement such function?

    Hi
    Please see below example from ABAPDOCU, this might help you.
    Internal Table cnt_tab is used to store class objects.
    Regards,
    Vishal
    REPORT demo_objects_references.
    CLASS counter DEFINITION.
      PUBLIC SECTION.
        METHODS: set IMPORTING value(set_value) TYPE i,
                 increment,
                 get EXPORTING value(get_value) TYPE i.
      PRIVATE SECTION.
        DATA count TYPE i.
    ENDCLASS.
    CLASS counter IMPLEMENTATION.
      METHOD set.
        count = set_value.
      ENDMETHOD.
      METHOD increment.
        ADD 1 TO count.
      ENDMETHOD.
      METHOD get.
        get_value = count.
      ENDMETHOD.
    ENDCLASS.
    DATA: cnt_1 TYPE REF TO counter,
          cnt_2 TYPE REF TO counter,
          cnt_3 TYPE REF TO counter,
          cnt_tab TYPE TABLE OF REF TO counter.
    DATA number TYPE i.
    START-OF-SELECTION.
      CREATE OBJECT: cnt_1,
                     cnt_2.
      MOVE cnt_2 TO cnt_3.
      CLEAR cnt_2.
      cnt_3 = cnt_1.
      CLEAR cnt_3.
      APPEND cnt_1 TO cnt_tab.
      CREATE OBJECT: cnt_2,
                     cnt_3.
      APPEND: cnt_2 TO cnt_tab,
              cnt_3 TO cnt_tab.
      CALL METHOD cnt_1->set EXPORTING set_value = 1.
      CALL METHOD cnt_2->set EXPORTING set_value = 10.
      CALL METHOD cnt_3->set EXPORTING set_value = 100.
      DO 3 TIMES.
        CALL METHOD: cnt_1->increment,
                     cnt_2->increment,
                     cnt_3->increment.
      ENDDO.
      LOOP AT cnt_tab INTO cnt_1.
        CALL METHOD cnt_1->get IMPORTING get_value = number.
        WRITE / number.
      ENDLOOP.

  • Create a JTable based on an ArrayList containing instances of a class.

    I have a class, IncomeBudgetItem, instances of which are contained in an ArrayList. I would like to create a JTable, based on this ArrayList. One variable is a string, while others are type double. Not all variables are to appear in the JTable.
    The internal logic of my program is already working. And my GUI is largely constructed. I'm just not sure how to make them talk to each other. The actually creation of the JTable is my biggest problem right now.

    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.util.ArrayList;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    public class TableDemo extends JPanel {
         private boolean DEBUG = false;
         public TableDemo() {
              super(new GridLayout(1, 0));
              ArrayList<MyObject> list = new ArrayList<MyObject>();
              list.add(new MyObject("Kathy", "Smith", "Snowboarding", new Integer(5),
                        new Boolean(false)));
              list.add(new MyObject("John", "Doe", "Rowing", new Integer(3),
                        new Boolean(true)));
              list.add(new MyObject("Sue", "Black", "Knitting", new Integer(2),
                        new Boolean(false)));
              list.add(new MyObject("Jane", "White", "Speed reading",
                        new Integer(20), new Boolean(true)));
              JTable table = new JTable(new MyTableModel(list));
              table.setPreferredScrollableViewportSize(new Dimension(500, 70));
              table.setFillsViewportHeight(true);
              // Create the scroll pane and add the table to it.
              JScrollPane scrollPane = new JScrollPane(table);
              // Add the scroll pane to this panel.
              add(scrollPane);
         class MyObject {
              String firstName;
              String lastName;
              String sport;
              int years;
              boolean isVeg;
              MyObject(String firstName, String lastName, String sport, int years,
                        boolean isVeg) {
                   this.firstName = firstName;
                   this.lastName = lastName;
                   this.sport = sport;
                   this.years = years;
                   this.isVeg = isVeg;
         class MyTableModel extends AbstractTableModel {
              private String[] columnNames = { "First Name", "Last Name", "Sport",
                        "# of Years", "Vegetarian" };
              ArrayList<MyObject> list = null;
              MyTableModel(ArrayList<MyObject> list) {
                   this.list = list;
              public int getColumnCount() {
                   return columnNames.length;
              public int getRowCount() {
                   return list.size();
              public String getColumnName(int col) {
                   return columnNames[col];
              public Object getValueAt(int row, int col) {
                   MyObject object = list.get(row);
                   switch (col) {
                   case 0:
                        return object.firstName;
                   case 1:
                        return object.lastName;
                   case 2:
                        return object.sport;
                   case 3:
                        return object.years;
                   case 4:
                        return object.isVeg;
                   default:
                        return "unknown";
              public Class getColumnClass(int c) {
                   return getValueAt(0, c).getClass();
          * Create the GUI and show it. For thread safety, this method should be
          * invoked from the event-dispatching thread.
         private static void createAndShowGUI() {
              // Create and set up the window.
              JFrame frame = new JFrame("TableDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // Create and set up the content pane.
              TableDemo newContentPane = new TableDemo();
              newContentPane.setOpaque(true); // content panes must be opaque
              frame.setContentPane(newContentPane);
              // Display the window.
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              // Schedule a job for the event-dispatching thread:
              // creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createAndShowGUI();
    }

  • How to create an instance of a class which is stored in a String?

    I've class name stored in a String Object.
    now i've to create an instance of that class name.
    How?

    This is very dangerous ground because you give up compile-time safety, but you can get a Class object using Class.forName(String). Then you can use methods of the class Class to operate on it (including creating an instance).

  • How to create an instance of a class which is actually an array?

    the following code gives a runtime exception
    Object obj = (Object )attributeClass.newInstance();
    Exception:
    java.lang.InstantiationException: [Ltest.Name;[/b]
    Here test.Name is user defined class and i want to create an array instance of that class.
    I have tried the following also:
    [b]Object methodArgs[] = new Object[length];
    for(int j=0;j<length;++j){
    methodArgs[j] = singleMemberClass.cast(testArray[j]);
    Object temp = attributeClass.cast(methodArgs);
    In the above code singleMemberClass is test.Name, but the last line gives the following exception.
    java.lang.ClassCastException
    Message was edited by:
    lalit_mangal
    Message was edited by:
    lalit_mangal

    Try the following code
    import java.lang.reflect.Array;
    public class TestReflection {
         public static void main(String args[]) {
              Object array = Array.newInstance(A.class, 3);
              printType(array);
         private static void printType(Object object) {
              Class type = object.getClass();
              if (type.isArray()) {
                   System.out.println("Array of: " + elementType);
              System.out.println("Array size: " + Array.getLength(object));
    class A{
    }

  • How do I make an instance of another class??

    How do I make an instance of a class, (eg. the name of the class is oldJava.class and have a constructor that takes 3 parameters)in a new class. and send paramaters to the oldJava.class constructor. I also want to recive the result from oldJava.class in my new class.
    ??I would be really glad if I could get some code example.....
    //HA

    oldJava o = new oldJava(..., ..., ...); // your arguments here
    o.method1(); // you can call methods on this object now
    // If the method returns anything back, you can keep a reference to it
    int result = o.sum(2, 5);

  • Adding a JPanel from one class to another Class (which extends JFrame)

    Hi everyone,
    So hopefully I go about this right, and I can figure out what I'm doing wrong here. As an exercise, I'm trying to write a Tic-Tac-Toe (TTT) game. However, in the end it will be adaptable for different variations of TTT, so it's broken up some. I have a TTTGame.java, and TTTSquareFrame.java, and some others that aren't relavent.
    So, TTTGame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              addPanel = startSimple();
              if(!addPanel.isValid())
                   System.out.println("Something's wrong");
              contents.add(addPanel);
              setSize(300, 300);
              setVisible(true);
         public JPanel startSimple()
              mainSquare = new TTTSquareFrame(sides);
              mainSquarePanel = mainSquare.createPanel(sides);
              return mainSquarePanel;
    }and TTTSquareFrame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.Misc;
    public class TTTSquareFrame
         private JPanel squarePanel;
         private JButton [] squares;
         private int square, index;
         public TTTSquareFrame()
              System.out.println("Use a constructor that passes an integer specifying the size of the square please.");
              System.exit(0);
         public TTTSquareFrame(int size)
         public JPanel createPanel(int size)
              square = (int)Math.pow(size, 2);
              squarePanel = new JPanel();
              squarePanel.setLayout(new GridLayout(3,3));
              squares = new JButton[square];
              System.out.println(MIN_SIZE.toString());
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setRolloverEnabled(false);
                   squares[i].addActionListener(bh);
                   //squares[i].setMinimumSize(MIN_SIZE);
                   squares[i].setVisible(true);
                   squarePanel.add(squares[i]);
              squarePanel.setSize(100, 100);
              squarePanel.setVisible(true);
              return squarePanel;
    }I've successfully added panels to JFrame within the same class, and this is the first time I'm modularizing the code this way. The issue is that the frame comes up blank, and I get the message "Something's wrong" and it says the addPanel is invalid. Originally, the panel creation was in the constructor for TTTSquareFrame, and I just added the mainSquare (from TTTGame class) to the content pane, when that didn't work, I tried going about it this way. Not exactly sure why I wouldn't be able to add the panel from another class, any help is greatly appreciated.
    I did try and cut out code that wasn't needed, if it's still too much let me know and I can try and whittle it down more. Thanks.

    Yea, sorry 'bout that, I just cut out the parts of the files that weren't relevant but forgot to compile it just to make sure I hadn't left any remnants of what I had removed. For whatever it's worth, I have no idea what changed, but something did and it is working now. Thanks for your help, maybe next time I'll post an actual question that doesn't somehow magically solve itself.
    EDIT: Actually, sorry, I've got the panel working now, but it's tiny. I've set the minimum size, and I've set the size of the panel, so...why won't it respond to that? It almost looks like it's being compressed into the top of the panel, but I'm not sure why.
    I've compressed the code into:
    TTTGame.java:
    import java.awt.*;
    import javax.swing.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              mainSquare = new TTTSquareFrame(sides.intValue());
              contents.add(mainSquare);
              setSize(400, 400);
              setVisible(true);
    }TTTSquareFrame.java
    import java.awt.*;
    import javax.swing.*;
    public class TTTSquareFrame extends JPanel
         private JButton [] squares;
         private int square, index;
         private final Dimension testSize = new Dimension(50, 50);
         public TTTSquareFrame(int size)
              super();
              square = (int)Math.pow(size, 2);
              super.setLayout(new GridLayout(size, size));
              squares = new JButton[square];
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setMinimumSize(testSize);
                   squares[i].setVisible(true);
                   super.add(squares[i]);
              setSize(200, 200);
              setVisible(true);
    I've made sure the buttons are smaller than the size of the panel, and the panel is smaller than the frame, so...
    Message was edited by:
    macman104

  • How to pass params to another class which accepts keyboard input?

    How can I pass params to a stand-alone Java class that, when executed, gathers params using readLine()?
    In other words, MyClass, when executed from the command-line, uses readLine to gather params for program execution. I'd like to test this class by calling it from another class using Runtime.exec("java MyClass") or calling MyClass.main(args) directly. But, how can I simulate the input expected from the keyboard?
    Thanks!

    Alright, so it looks like this:
    proc = Runtime.getRuntime().exec("java Client");
    br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
    bw = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
    bw.write("test");
    bw.newLine();
    But, how can write doesn't seem to be passed to the original client class.
    Suggestions?

  • Creating value set one dependent n another

    Hi,
    I want to create 2 custom value sets XX_PARTY_NUMBER and XX_CUSTOMER_NUMBER
    When i select the value for Party_number from XX_PARTY_NUMBER,
    the corresponding customer_number should populate from XX_CUSTOMER_NUMBER
    This is what i tried
    1ST VALUE SET
    VALUE_SET_NAME -- XX_PARTY_NUMBER
    APPLICATION ---RECEIVABLES
    TABLE HZ_PARTIES
    VALUE-- PARTY_NUMBER
    MEANING PARTY_NAME
    ID-- PARTY_ID
    WHERE_CLAUSE -- ORDER BY PARTY_ID ASC
    2ND VALUE SET
    VALUE_SET_NAME
    XX_CUSTOMER_NUMBER
    APPLICATION -- RECEIVABLES
    TABLE --- RA_CUSTOMERS
    VALUE -- CUSTOMER_NAME
    MEANING -- CUSTOMER_NUMBER
    ID ---
    WHERE_CLAUSE-- PARTY_ID IN :$FLEX$.XX_PARTY_NUMBER
    I'm not getting it correctly.
    Can you help me?

    Try changing the where clause in the second value set:
    WHERE_CLAUSE-- PARTY_ID = :$FLEX$.XX_PARTY_NUMBER
    other than that i dont see any issues.
    Thanks,
    raj

  • Create a new instance of a class without starting new windows.

    I've a class with basic SWING functions that displays an interface. Within this class is a method which updates the status bar on the interface. I want to be able to reference this method from other classes in order to update the status bar. However, in order to do this, I seem to have to create a new instance of the class which contains the SWING code, and therefore it creates a new window.
    Can somebody give me an example, showing how I might update a component on the interface without a new window being created.
    Many thanks in advance for any help offererd.

    I've a class with basic SWING functions that displays
    an interface. Within this class is a method which
    updates the status bar on the interface. I want to be
    able to reference this method from other classes in
    order to update the status bar. However, in order to
    do this, I seem to have to create a new instance of
    the class which contains the SWING code, and
    therefore it creates a new window.
    Can somebody give me an example, showing how I might
    update a component on the interface without a new
    window being created.
    Many thanks in advance for any help offererd.It sounds like you have a class that extends JFrame or such like and your code must be going
               Blah  test = new Blah();
                test.showStatus("text");Whereas all you need is a reference to that Classs.
    So in your class with basic SWING functions that displays an interface.
    You Might have something like this
              // The Label for displaying Status messages on
              JLabel statusLabel = new JLabel();
              this.add( statusLabel , BorderLayout.SOUTH );What you want to do is provide other Classes a 'method' for changing your Status Label, so in that class you might do something like:
          Allow Setting of Text in A JLabel From various Threads.
         And of course other classes......
         The JLabel statusLabel is a member of this class.
         ie defined in this class.
        @param inText    the new Text to display
       public void setStatusText( String inText )
                    final String x = inText;
                    SwingUtilities.invokeLater( new Runnable()
                              public void run()
                                       statusLabel.setText( x );
      }You still need a reference to your first class in your second class though.
    So you might have something like this:
            private firstClass firstClassReference;        // Store Reference
            public secondClass(  firstClass  oneWindow )
                          // create whatever.........
                         this.firstClassReference = oneWindow;
    // blah blah.
          private someMethod()
                            firstClassReference.setStatusText( "Hello from Second Class");
        }Hope that gives you some ideas

  • How do I create an genericized instance of this class?

    Hi, I'm having trouble creating a proper generic instance of this class that I wrote. The class type is cyclic dependant on itself.
    public class MyClass<T extends MyClass<T>>
    I can create an instance like this:
    MyClass<?> class = new MyClass();But I would be mixing raw types and generic types.
    Is there anyway to create a proper generic instance of MyClass?
    Thanks a lot
    -Cuppo

    Ah thanks georgemc,
    your solution will certainly work.
    If i may ask your opinion of something...
    MyClass is designed such that the type parameter should always be the same as the class itself. It's kinda a hack to get the subclass type from the superclass.
    so a hierarchy looks something like this:
    class MyClass<T extends MyClass<T> >
    class SubClass<T extends SubClass<T>> extends MyClass<T>
    class FinalSubClass extends SubClass<FinalSubClass>So ideally i would want something like:
    MyClass m = new MyClass<MyClass>();
    (which is not possible)
    is there a way to get around this?
    -Cuppo

  • Value from JDialog to another class

    Hi:
    I have a trouble with getting my values from a JDialog box to another class.
    Here's what I have:
    This is an ftp application. I have a main frame where if the user selects File->New Connection
    it pops up a Connect dialog box. The connect dialog box has various fields such as profile name, host address, user name, and so on. In addition, there are three buttons, Add, Connect and Cancel.
    After the user types info and clicks Connect, all these information should be sent to the main frame from where it would send the information to another class which would connect to the ftp server.
    I have a class called Profile which is used to wrap these information to be sent to the main frame.
    Now, how can i get this info to the main frame? Here's the code in main frame:
    class MainFrame extends JFrame {
    JMenuItem newconnection = new JMenuItem("New Connection", 'N');
    newconnection.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    Profile p = new Profile();
    ConnectDialog con = new ConnectDialog();
    p = con.getProfile();
    makeNewConnection(p); //this is the method i use to make a new connection
    The problem is that by the time i get to the line p = con.getProfile(),
    con object no longer exists.
    Should i use threads or should i just send the main frame as the parameter to create the Connect dialog. If i use threads, how should i code it, and if i use main frame as the parent frame for connect dialog, how do i get the info to main frame. Please help. Here's the code for ConnectDialog. Also, please advice if ConnectDialog code can be improved since i am new to swing. Thanks for helping a needy student.
    public class ConnectDialog extends JDialog{
    private MainFrame parent;
    private String defaultDownloadPath;
    private static Profile currProfile;
    private JList profileList;
    private JPanel listPanel;
    private JPanel infoPanel;
    private JPanel labelPanel;
    private JPanel buttonPanel;
    private JPanel arrangedComponents;
    private Vector data;
    private JLabel ProfileName;
    private JLabel HostAddress;
    private JLabel Account;
    private JLabel PortNo;
    private JLabel login;
    private JLabel password;
    private JLabel DownLoadPath;
    private JButton addButton;
    private JButton cancelButton;
    private JButton connectButton;
    private JButton browseButton;
    private JButton clearButton;
    private JLabel Anonymous;
    private JCheckBox anonymous;
    private JTextField profileName;
    private JTextField hostAddress;
    private JTextField account;
    private JTextField portNo;
    private JTextField loginName;
    private JTextField passwd;
    private JTextField downloadPath;
    private final int textSize = 20;
    private final int fontSize = 12;
    private Container cp;
    public ConnectDialog(MainFrame main) {
    super(main, true);
    parent = main;
    data = new Vector();
    currProfile = new Profile();
    profileList = new JList(data);
    listPanel = new JPanel();
    labelPanel = new JPanel();
    infoPanel = new JPanel();
    buttonPanel = new JPanel();
    arrangedComponents = new JPanel();
    ProfileName = new JLabel("Profile Name:");
    ProfileName.setForeground(Color.black);
    HostAddress = new JLabel("Host Address:");
    HostAddress.setForeground(Color.black);
    Account = new JLabel("Account:");
    Account.setForeground(Color.black);
    PortNo = new JLabel("Port:");
    PortNo.setForeground(Color.black);
    login = new JLabel("Login:");
    login.setForeground(Color.black);
    password = new JLabel("Password:");
    password.setForeground(Color.black);
    DownLoadPath = new JLabel("Download Path:");
    DownLoadPath.setForeground(Color.black);
    addButton = new JButton("Add");
    addButton.setMnemonic('A');
    addButton.setForeground(Color.black);
    cancelButton = new JButton("Cancel");
    cancelButton.setForeground(Color.black);
    clearButton = new JButton("Clear");
    clearButton.setForeground(Color.black);
    connectButton = new JButton("Connect");
    connectButton.setForeground(Color.black);
    connectButton.setMnemonic('C');
    browseButton = new JButton("Browse");
    browseButton.setForeground(Color.black);
    browseButton.setMnemonic('B');
    Anonymous = new JLabel("Anonymous: ");
    Anonymous.setForeground(Color.black);
    anonymous = new JCheckBox();
    profileName = new JTextField(textSize);
    profileName.setText("");
    profileName.setBorder(BorderFactory.createLoweredBevelBorder());
    profileName.setBorder(BorderFactory.createLineBorder(Color.black));
    profileName.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    hostAddress = new JTextField(textSize);
    hostAddress.setText("");
    hostAddress.setBorder(BorderFactory.createEtchedBorder());
    hostAddress.setBorder(BorderFactory.createLineBorder(Color.black));
    hostAddress.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    account = new JTextField(textSize);
    account.setText("");
    account.setBorder(BorderFactory.createLoweredBevelBorder());
    account.setBorder(BorderFactory.createLineBorder(Color.black));
    account.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    portNo = new JTextField(5);
    portNo.setText("");
    portNo.setText("21");
    portNo.setBorder(BorderFactory.createEtchedBorder());
    portNo.setBorder(BorderFactory.createLineBorder(Color.black));
    portNo.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    loginName = new JTextField(textSize);
    loginName.setText("");
    loginName.setBorder(BorderFactory.createEtchedBorder());
    loginName.setBorder(BorderFactory.createLineBorder(Color.black));
    loginName.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    passwd = new JTextField(textSize);
    passwd.setText("");
    passwd.setBorder(BorderFactory.createEtchedBorder());
    passwd.setBorder(BorderFactory.createLineBorder(Color.black));
    passwd.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    downloadPath = new JTextField(textSize);
    downloadPath.setText("");
    downloadPath.setBorder(BorderFactory.createEtchedBorder());
    downloadPath.setBorder(BorderFactory.createLineBorder(Color.black));
    downloadPath.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    cp = this.getContentPane();
    this.setBounds(200,200,600,300);
    this.setResizable(false);
    cp.setLayout(new BorderLayout());
    setListPanel();
    setLabelPanel();
    setButtonPanel();
    setActionListeners();
    this.setBackground(Color.lightGray);
    this.setVisible(true);
    this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    public String getDefaultDownloadPath() {
    return defaultDownloadPath;
    // public Profile getProfile() {
    // try {
    // this.wait();
    // } catch (Exception e) {}
    // return currProfile;
    public void setListPanel() {
    profileList.setFont(new Font("Dialog", Font.PLAIN, 12));
    profileList.setBackground(Color.white);
    profileList.setForeground(Color.black);
    profileList.setPrototypeCellValue("MMMMMMMMM");
    listPanel.setPreferredSize(profileList.getPreferredScrollableViewportSize());
    listPanel.setBorder(BorderFactory.createEtchedBorder());
    listPanel.setBorder(BorderFactory.createLineBorder(Color.black));
    listPanel.setBackground(Color.white);
    listPanel.add(profileList);
    cp.add(listPanel, "West");
    public void setLabelPanel() {
    arrangedComponents = new JPanel();
    arrangedComponents.setLayout(new BorderLayout());
    labelPanel = new JPanel();
    labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));
    labelPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
    JPanel row1 = new JPanel();
    row1.add(ProfileName);
    labelPanel.add(row1);
    JPanel row2 = new JPanel();
    row2.add(HostAddress);
    labelPanel.add(row2);
    JPanel row3 = new JPanel();
    row3.add(Account);
    labelPanel.add(row3);
    JPanel row4 = new JPanel();
    row4.add(PortNo);
    labelPanel.add(row4);
    JPanel row5 = new JPanel();
    row5.add(login);
    labelPanel.add(row5);
    JPanel row6 = new JPanel();
    row6.add(password);
    labelPanel.add(row6);
    JPanel row7 = new JPanel();
    row7.add(DownLoadPath);
    labelPanel.add(row7);
    infoPanel.setLayout(new BoxLayout(infoPanel,BoxLayout.Y_AXIS));
    infoPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
    row1 = new JPanel();
    row1.add(profileName);
    row1.add(profileName);
    infoPanel.add(row1);
    row2 = new JPanel();
    row2.add(hostAddress);
    row2.add(hostAddress);
    infoPanel.add(row2);
    row3 = new JPanel();
    row3.add(account);
    infoPanel.add(row3);
    row4 = new JPanel();
    row4.setLayout(new FlowLayout());
    row4.add(portNo);
    row4.add(Box.createHorizontalStrut(57));
    row4.add(Anonymous);
    row4.add(anonymous);
    infoPanel.add(row4);
    row5 = new JPanel();
    row5.add(loginName);
    infoPanel.add(row5);
    row6 = new JPanel();
    row6.add(passwd);
    infoPanel.add(row6);
    row7 = new JPanel();
    row7.setLayout(new FlowLayout());
    row7.add(downloadPath);
    row7.add(browseButton);
    infoPanel.add(row7);
    arrangedComponents.add(labelPanel, "West");
    arrangedComponents.add(infoPanel, "Center");
    cp.add(arrangedComponents, "Center");
    public void setButtonPanel() {
    buttonPanel.setLayout(new FlowLayout());
    buttonPanel.add(addButton);
    buttonPanel.add(connectButton);
    buttonPanel.add(cancelButton);
    buttonPanel.add(clearButton);
    cp.add(buttonPanel, "South");
    public void setActionListeners() {
    anonymous.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         if(anonymous.isSelected()) {
         loginName.setText("anonymous");
         passwd.setText("your email here");
         else {
         loginName.setText("");
         passwd.setText("");
    addButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         if(profileName.getText() != "" && !data.contains(profileName.getText())){
         data.add(profileName.getText());
         profileList.setListData(data);
    connectButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         connectButtonPressed();
    cancelButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         JButton b = (JButton) e.getSource();
         ConnectDialog c = (ConnectDialog) b.getTopLevelAncestor();
         c.dispose();
    clearButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         profileName.setText("");
         hostAddress.setText("");
         account.setText("");
         portNo.setText("");
         loginName.setText("");
         passwd.setText("");
         downloadPath.setText("");
    browseButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         JFrame browseFrame = new JFrame("browse for folder");
         browseFrame.setBounds(230,230,200,200);
         JDirectoryChooser fileChooser = new JDirectoryChooser();
         fileChooser.setFileSelectionMode(JDirectoryChooser.DIRECTORIES_ONLY);
         int option = fileChooser.showDialog(browseFrame);
         if(option==JFileChooser.APPROVE_OPTION) {
         File f = fileChooser.getSelectedFile();
         defaultDownloadPath = f.getAbsolutePath();
         downloadPath.setText(defaultDownloadPath);
    public void connectButtonPressed() {
    if(!profileName.getText().equals("") && !hostAddress.getText().equals("") &&
    !loginName.getText().equals("") && !passwd.getText().equals("")) {
    currProfile.setProfileName(profileName.getText());
    currProfile.setHostAddress(hostAddress.getText());
    currProfile.setAcct(account.getText());
    currProfile.setUserName(loginName.getText());
    currProfile.setPassword(passwd.getText());
    currProfile.setDownloadPath(downloadPath.getText());
    parent.setProfile(currProfile);
    this.dispose();
    else {
    JFrame f = new JFrame("Error!");
    JOptionPane.showMessageDialog(f, "Some fields empty!", "", JOptionPane.ERROR_MESSAGE);
    }

    If the dialog is modal then you can just call show and wait for it to close by the user, then grab the info:
    ConnectDialog dialog = new ConnectDialog();
    dialog .show();
    Profile profile = con.getProfile();
    makeNewConnection( profile );

  • Using an int from one class in another class

    I am a student writing a java program on renewable energy. Simply I have a power output which is a variable called PowerOutPut. declared as (public int PowerOutPut) I have another class which is a graphics class where I display the variable PowerOutPut on a graph, but i dont know how to call this variable in my graphics class.
    if anyone can help, I would be very grateful.
    Chris

    But bear in mind that it is good practice to declare your variables private (unless you need otherwise) and to provide get and set methods to access and change them.
    private int myVariable = 0;
    public int getMyVariable(){
        return myVariable;
    public void setMyVariable(int newValue){
        myVariable = newValue;
    }Also, class names should start with upper case and variables should start with lower case.
    Good luck.

  • Calling a method within a class form another class(ViewController)

    I am creating an SQL project in XCODE. I have one view. My main view controller is loading the database to a table/array. I want to add another class (with no NIB) just to handle the display of the table in a UITableView. So, I added a skeleton cocoa touch class file to my classes folder to handle this function when parameters change.
    So, in my app delegate, the "applicationdidFinishLaunchingWithOptions" method loads my mainViewController and NIB.  On the "viewDidLoad" method in my mainViewController, I read a URL into an SQLite database and close the database.  Herein lies the problem: I want to call my new class (TableViewHandler) and pass it the array created in the mainViewController and use the array to populate the UITable.
    How do I call a class from within another class (which has no NIB) to populate the table?  Especially if my TableViewHandler has no "viewDidLoad", "viewDidAppear", etc.
    Regads,
    -Kevin

    This is what my exact problem.
    i've created a bean (DataBean) to access the database. i'm having a servlet program (ShopBook). now to check some details over there in the database from the servlet i'm in need to use a method in the DataBean.
    both ShopBook.java and DataBean.java lies in the package shoppack.
    in ShopBook i tried to instantiate the object to DataBean as
    DataBean db = new DataBean();
    it shows the compiler error, unable to resolve symbol DataBean.
    note:
    first i compiled DataBean.java, it got compiled perfectly and the class file resides inside the shoppack.
    when i'm trying to compile the ShopBook its telling this error.
    hope i'm clear in explaining my problem. can u please help me?
    thank u in advance.
    regards,
    Fazli

  • Can't add list element when calling a method from another class

    I am trying to call a method in another class, which contains code listmodel.addElement("text"); to add an element into a list component made in that class.
    I've put in System.out.println("passed"); in the method just to make sure if the method was being called properly and it displays normally.
    I can change variables in the other class by calling the method with no problem. The only thing I can't do is get listmodel.addElement("text"); to add a new element in the list component by doing it this way.
    I've called that method within it's class and it added the element with no problem. Does Java have limitations about what kind of code it can run from other classes? And if that's the case I'd really like to know just why.

    There were no errors, just the element doesnt get added to the list by doing it this way
    class showpanel extends JPanel implements ActionListener, MouseMotionListener {
           framepanel fp = new framepanel();
           --omitted--
         public void actionPerformed(ActionEvent e){
                  if(e.getSource() == button1){
                       fp.addLayer();
    /*is in a different class file*/
    class framepanel extends JPanel implements ActionListener{
            --omitted--
         public void addLayer(){
              listmodel.addElement("Layer"+numLayer);
              numLayer++;
    }

Maybe you are looking for

  • Exchange 2013 Window Backup failure - fails to clean up log files - error FFFFFFFC

    Hello, We currently have an Exchange 2013 - Exchange 2007 coexistence setup. 1x Windows Server 2008 R2 with Exchange 2007 CAS/HUB 1x Windows Server 2008 R2 with Exchange 2007 MBX 1x Windows Server 2008 R2 with Exchange 2013 CU 3 (all roles) Since our

  • Connection to "Central" Services Registry from Visual composer not working

    Hi Folks, We are having issues connecting to the Services registry from the Visual Composer. The search on services in the services registry does not yield any results. We have configured the NWA page as mentioned on the "Configuring the Services Reg

  • Error: Different types for "?:" (? and void)

    This error occures while compiling the following code line: straight * stra = new straight( p1, (p2 - p1).uvec3() ); the error doesn't appear if the code looks like: unitvec3 uv = (p2-p1).uvec3(); straight * stra = new straight( p1, uv ); in a mailin

  • MacBook Pro Bluetooth won't connect with iPhone4s

    I am trying to connect my iPhone 4s bluetooth with my Macbook pro, but it won't let me connect . Sometimes it would say "Andrew's Mac Book is not a supported device" or  "Make sure 'Andrew's Mac Book Pro' is turned on and in range" (My macbook is rig

  • Setting default date @prompt

    I have a @prompt filter like this: Table.Datecolumn     >=  @Prompt('Start Date  ','D',,mono,free)  and Table.Datecolumn     <=   @Prompt('End date','D',,mono,free) I like to set the start date defaulted to '07/01/2009'..so that user need not enter a