Java Forum / GUI / March 2006
GUI
L - 15 Mar 2006 03:46 GMT Hi Team,
Iam a new learner to Java and Swing. I dont have any programming experience before. Iam trying to create a GUI with a Textarea to enter the query terms, Get Abstracts button and two scroll panes with text "Abstracts returned" and "Total Abstract" when we click on one of the
"Abstracts returned" from the list.
1. Textarea to enter the query terms 2."Get Abstracts" button 3. scroll pane list with text "Abstracts returned" 4. second scroll pane with text "Total Abstract" when we click on one of the "Abstracts returned" from the list.
I have written the below code, and got the below error
Assistant.java:221: 'class' or 'interface' expected private static void createAndShowGUI() { ^
MY CODE
import javax.swing.*; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JButton;
import javax.swing.JTextPane; import javax.swing.JScrollPane; import java.awt.Label; import java.awt.List;
/** * @abc * */ public class Assistant extends Jpanel { private static Assistant m_instance;
private JTextArea jTextArea = null;
private JButton jButton = null; private List list = null;
private List list1 = null;
private JTextPane jTextPane = null;
private JScrollPane jScrollPane = null;
private Label label = null;
private Label label1 = null;
private Label label2 = null;
public static Assistant getInstance() { if (m_instance == null) m_instance = new Assistant(); return m_instance; }
/** * This method initializes this * * @return void */ private void initialize() { label2 = new Label(); label1 = new Label(); label = new Label(); this.setLayout(null);
this.setSize(1000, 700); label.setBounds(154, 20, 171, 23); label.setText("Please enter query terms:"); label1.setBounds(11, 173, 194, 23); label1.setText(" Abstracts returned: 0"); label2.setBounds(11, 426, 196, 23); label2.setText(" Abstracts: 0"); this.add(getJTextArea(), null); this.add(getList1(), null); this.add(getJScrollPane(), null); this.add(label, null); this.add(label1, null); this.add(getJButton(), null); this.add(getList(), null); this.add(label2, null); this.add(getList2(), null); }
/** * This method resets jList, jList1 and jTextPane * * @void */ private void reset() { list.removeAll(); list1.removeAll(); list2.removeAll(); label1.setText("Please enter query terms: 0"); label2.setText(" Abstracts returned: 0");
jTextPane.setText(""); }
/** * This method set button enable or not * * @void */ public void setButtonEnable(boolean enable) { jButton.setEnabled(enable); }
/** * This method add Abstracts to list * * @void */ public void addSequenceAbstracts() { list.add(abstracts); label1.setText(" Abstracts returned: " + list.getItemCount()); }
/** * This method returns jTextArea * * @return javax.swing.JTextArea */ private JTextArea getJTextArea() { if (jTextArea == null) { jTextArea = new JTextArea(); jTextArea.setText("This " + "text area " + "display " + "in any font"); textArea.setFont(new Font("Serif", Font.ITALIC, 16)); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); } return jTextArea; }
/** * This method returns list1 * * @return java.swt.List */ private List getList1() { if (list1 == null) { list1 = new List(); list1.setBounds(12, 453, 182, 201); } return list1; }
/** * This method returns jTextPane * * @return javax.swing.JTextPane */ private JTextPane getJTextPane() { if (jTextPane == null) { jTextPane = new JTextPane(); jTextPane.setContentType("text/html"); } return jTextPane; }
/** * This method returns jButton * * @return javax.swing.JButton */ private JButton getJButton() { if (jButton == null) { jButton = new JButton(); jButton.setText("Get Abstracts"); jButton.setBounds(440, 19, 164, 28);
} return jButton; }
/** * This method returns jList * * @return java.swt.List */ private List getList() { if (list == null) { list = new List(); list.setBounds(11, 200, 182, 215);
} return list; }
/** * This method returns jScrollPane * * @return javax.swing.JScrollPane */ private JScrollPane getJScrollPane() { if (jScrollPane == null) { jScrollPane = new JScrollPane(); jScrollPane.setBounds(212, 70, 770, 585); jScrollPane.setViewportView(getJTextPane()); } return jScrollPane; }
private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window. JFrame frame = new JFrame("Assistant"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add the ubiquitous " Assistant" label. JLabel label = new JLabel(" Assistant"); frame.getContentPane().add(label);
//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(); } }); }
}
It would be great if somebody help me to overcome the problem. Also any
suggestions to improve my programming are welcome.
Thanks, -L
IchBin - 15 Mar 2006 07:56 GMT > Hi Team, > > Iam a new learner to Java and Swing. I dont have any programming > experience before. Iam trying to create a GUI with a Textarea to enter > the query terms, Get Abstracts button and two scroll panes with text [snip]
> import javax.swing.*; > import javax.swing.JPanel; [quoted text clipped - 5 lines] > import java.awt.Label; > import java.awt.List; use these imports:
import java.awt.Font;
import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextPane;
[snip]
> public class Assistant extends Jpanel { public class Assistant extends JPanel {
[snip]
> private List list = null; > private List list1 = null; private JList list = null; private JList list1 = null;
> private Label label = null; > private Label label1 = null; > private Label label2 = null; private JLabel label = null; private JLabel label1 = null; private JLabel label2 = null;
[snip]
> this.add(getList2(), null); You have not defined this method: getList2()
[snip]
> list2.removeAll(); You have not defined this object: list2
[snip]
> public void addSequenceAbstracts() > { > list.add(abstracts); This abstracts object is never defined
> label1.setText(" Abstracts returned: " + > list.getItemCount()); label1.setText(" Abstracts returned: " + list.getModel().getSize());
[snip]
> textArea.setFont(new Font("Serif", Font.ITALIC,16)); > textArea.setLineWrap(true); > textArea.setWrapStyleWord(true); jTextArea.setFont(new Font("Serif", Font.ITALIC,16)); jTextArea.setLineWrap(true); jTextArea.setWrapStyleWord(true);
> private List getList1() { > if (list1 == null) { [quoted text clipped - 3 lines] > return list1; > } private JList getList1() { if (list1 == null) { list1 = new JList(); list1.setBounds(12, 453, 182, 201); } return list1; }
> private List getList() > { [quoted text clipped - 5 lines] > return list; > } private JList getList() { if (list == null) { list = new JList(); list.setBounds(11, 200, 182, 215); } return list; }
[snip]
> It would be great if somebody help me to overcome the problem. Also any > > suggestions to improve my programming are welcome. > > Thanks, > -L You have more errors then the one mentioned. In fact the error you mentioned did not appear for me. I have not looked to see if the code works but make the above changes and it will compile. Just come back for more help.
Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
L - 15 Mar 2006 14:53 GMT Hi IchBin,
Thanks for your help. As i told, iam new to this programming life[Basically a biology student] and learning the GUI stuff for one of my course project work. I made the necessary corrections as you suggested and i did run the program, but was able to open a window as you see in first HelloWorldSwing program. i didnot get any text boxes, button, and scrol panes. Please let me know what i need to do further. Here is my code,
import java.awt.Font; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextPane;
/** * @abc * */ public class Assistant extends JPanel {
private static Assistant m_instance;
private JTextArea jTextArea = null;
private JButton jButton = null;
private JList list = null;
private JList list1 = null;
private JTextPane jTextPane = null;
private JScrollPane jScrollPane = null;
private JLabel label = null;
private JLabel label1 = null;
private JLabel label2 = null;
public static Assistant getInstance() { if (m_instance == null) m_instance = new Assistant(); return m_instance; }
/** * This method initializes this * * @return void */ private void initialize() { label2 = new JLabel(); label1 = new JLabel(); label = new JLabel(); this.setLayout(null);
this.setSize(1000, 700); label.setBounds(154, 20, 171, 23); label.setText("Please enter query terms:"); label1.setBounds(11, 173, 194, 23); label1.setText("Abstracts returned: 0"); label2.setBounds(11, 426, 196, 23); label2.setText("Abstracts: 0"); this.add(getJTextArea(), null); this.add(getList1(), null); this.add(getJScrollPane(), null); this.add(label, null); this.add(label1, null); this.add(getJButton(), null); this.add(getList(), null); this.add(label2, null); }
/** * This method resets jList, jList1 and jTextPane * * @void */ private void reset() { list.removeAll(); list1.removeAll(); label1.setText("Please enter query terms: 0"); label2.setText("Abstracts returned: 0");
jTextPane.setText(""); }
/** * This method set button enable or not * * @void */ public void setButtonEnable(boolean enable) { jButton.setEnabled(enable); }
/** * This method add Abstracts to list * * @void */ public void addSequenceAbstracts() { label1.setText(" Abstracts returned: " + list.getModel().getSize()); }
/** * This method returns jTextArea * * @return javax.swing.JTextArea */ private JTextArea getJTextArea() { if (jTextArea == null) { jTextArea = new JTextArea(); jTextArea.setText("This " + "text area " + "display " + "in any font"); jTextArea.setFont(new Font("Serif", Font.ITALIC,16)); jTextArea.setLineWrap(true); jTextArea.setWrapStyleWord(true);
} return jTextArea; }
/** * This method returns list1 * * @return java.swt.List */ private JList getList1() { if (list1 == null) { list1 = new JList(); list1.setBounds(12, 453, 182, 201); } return list1; }
/** * This method returns jTextPane * * @return javax.swing.JTextPane */ private JTextPane getJTextPane() { if (jTextPane == null) { jTextPane = new JTextPane(); jTextPane.setContentType("text/html"); } return jTextPane; }
/** * This method returns jButton * * @return javax.swing.JButton */ private JButton getJButton() { if (jButton == null) { jButton = new JButton(); jButton.setText("Get Abstracts"); jButton.setBounds(440, 19, 164, 28);
} return jButton; }
/** * This method returns jList * * @return java.swt.List */ private JList getList() { if (list == null) { list = new JList(); list.setBounds(11, 200, 182, 215); } return list; }
/** * This method returns jScrollPane * * @return javax.swing.JScrollPane */ private JScrollPane getJScrollPane() { if (jScrollPane == null) { jScrollPane = new JScrollPane(); jScrollPane.setBounds(212, 70, 770, 585); jScrollPane.setViewportView(getJTextPane()); } return jScrollPane; }
private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window. JFrame frame = new JFrame("Assistant"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add the ubiquitous "Assistant" label. JLabel label = new JLabel("Assistant"); frame.getContentPane().add(label);
//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(); } }); } }
Thanks, Learner
IchBin - 15 Mar 2006 20:24 GMT > Hi IchBin, > [quoted text clipped - 5 lines] > button, and scrol panes. Please let me know what i need to do further. > Here is my code, Look like you just tried to copy code from here and there trying to formalized an executable java program. Guess you have to start some where. Are you using an IDE to build this program?
The problem you have is that you never load the JPanel that you build you GUI objects on into the frame ContentPane. You only load a label: frame.getContentPane().add(label);
I would try these changes.. You will have to add code to you button to do some processing. This should at least show the GUI objects you wanted to display in the frame. You can fool around with it now. These changes should get you going in the right direction. You still have a few tings to do to get what you want..
> import java.awt.Font; > import javax.swing.JButton; [quoted text clipped - 11 lines] > */ > public class Assistant extends JPanel { You do not have to extend JPanel. We will explicitly build it later. public class Assistant {
> private static Assistant m_instance; private JPanel pane;
private JTextArea jTextArea; private JButton jButton; private JList list; private JList list1; private JTextPane jTextPane; private JScrollPane jScrollPane; private JLabel label; private JLabel label1; private JLabel label2;
Add this import javax.swing.JPanel;
> public static Assistant getInstance() { > if (m_instance == null) > m_instance = new Assistant(); > return m_instance; > } You are not using the getInstance() method, you can remove it. I know what you are tying to do but do it somewhere else..
Add a constructor and call the createAndShowGUI();
Assistant() { createAndShowGUI(); }
> /** > * This method initializes this > * > * @return void > */ > private void initialize() { pane = new JPanel(); pane.setLayout(null);
label = new JLabel("Abstracts: 0"); label.setBounds(154, 20, 171, 23); label1 = new JLabel("Abstracts returned: 0"); label1.setBounds(11, 173, 194, 23); label2 = new JLabel("Please enter query terms:"); label2.setBounds(11, 426, 196, 23);
pane.setLayout(null); pane.setSize(1000, 700); pane.add(getJTextArea()); pane.add(getList1()); pane.add(getJScrollPane()); pane.add(label); pane.add(label1); pane.add(getJButton()); pane.add(getList()); pane.add(label2);
We are explicitly building a pane object to add to the frame content.
> } > [quoted text clipped - 40 lines] > private JTextArea getJTextArea() > {
> jTextArea = new JTextArea(); > jTextArea.setText("This " + "text area " + "display " + "in any > font"); > jTextArea.setFont(new Font("Serif", Font.ITALIC,16)); > jTextArea.setLineWrap(true); > jTextArea.setWrapStyleWord(true);
> return jTextArea; > } [quoted text clipped - 6 lines] > private JList getList1() > {
> list1 = new JList(); > list1.setBounds(12, 453, 182, 201);
> return list1; > } [quoted text clipped - 5 lines] > */ > private JTextPane getJTextPane() {
> jTextPane = new JTextPane(); > jTextPane.setContentType("text/html");
> return jTextPane; > } [quoted text clipped - 6 lines] > private JButton getJButton() > {
> jButton = new JButton(); > jButton.setText("Get Abstracts"); > jButton.setBounds(440, 19, 164, 28);
> return jButton; > } [quoted text clipped - 6 lines] > private JList getList() > {
> list = new JList(); > list.setBounds(11, 200, 182, 215);
> return list; > } [quoted text clipped - 6 lines] > private JScrollPane getJScrollPane() > {
> jScrollPane = new JScrollPane(); > jScrollPane.setBounds(212, 70, 770, 585); > jScrollPane.setViewportView(getJTextPane());
> return jScrollPane; > } > > private static void createAndShowGUI() { > //Make sure we have nice window decorations. get rid of next line
> JFrame.setDefaultLookAndFeelDecorated(true) change and add .. need to call your init method to build your GUI panel
initialize();
> //Create and set up the window. > JFrame frame = new JFrame("Assistant"); frame.setDefaultLookAndFeelDecorated(true);
> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); > > //Add the ubiquitous "Assistant" label. > JLabel label = new JLabel("Assistant"); > frame.getContentPane().add(label); Don't know what the above Label is for or if needed.
frame.getContentPane().add(pane);
> //Display the window. > frame.pack(); [quoted text clipped - 10 lines] > }); > } replace the main method content with: new Assistant();
> } > > Thanks, > Learner
 Signature Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
L - 16 Mar 2006 04:48 GMT Hi IchBin,
I got your point.I made the changes as you suggested, but still on the same path,. I think, iam missing something to add the Panel to JFrame. could you please help me in this.
import java.awt.Font;
import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextPane;
/** * @abc * */ public class Assistant {
private JPanel pane = null; private JTextArea jTextArea = null; private JButton jButton = null; private JList list = null; private JList list1 = null; private JTextPane jTextPane = null; private JScrollPane jScrollPane = null; private JLabel label = null; private JLabel label1 = null; private JLabel label2 = null;
public Assistant() { createAndShowGUI(); }
private void initialize() { pane = new JPanel(); pane.setLayout(null);
label = new JLabel("Abstracts: 0"); label.setBounds(154, 20, 171, 23); label1 = new JLabel("Abstracts returned: 0"); label1.setBounds(11, 173, 194, 23); label2 = new JLabel("Please enter query terms:"); label2.setBounds(11, 426, 196, 23);
pane.setLayout(null); pane.setSize(1000, 700); pane.add(getJTextArea()); pane.add(getList1()); pane.add(getJScrollPane()); pane.add(label); pane.add(label1); pane.add(getJButton()); pane.add(getList()); pane.add(label2); }
/** * This method resets jList, jList1 and jTextPane * * @void */ private void reset() { list.removeAll(); list1.removeAll(); label1.setText("Please enter query terms: 0"); label2.setText("Abstracts returned: 0"); jTextPane.setText(""); }
/** * This method set button enable or not * * @void */ public void setButtonEnable(boolean enable) { jButton.setEnabled(enable); }
/** * This method add Abstracts to list * * @void */ public void addSequenceAbstracts() { label1.setText(" Abstracts returned: " + list.getModel().getSize()); }
/** * This method returns jTextArea * * @return javax.swing.JTextArea */ private JTextArea getJTextArea() { if (jTextArea == null) { jTextArea = new JTextArea(); jTextArea.setText("This " + "text area " + "display " + "in any font"); jTextArea.setFont(new Font("Serif", Font.ITALIC,16)); jTextArea.setLineWrap(true); jTextArea.setWrapStyleWord(true); } return jTextArea; }
/** * This method returns list1 * * @return java.swt.List */ private JList getList1() { if (list1 == null) { list1 = new JList(); list1.setBounds(12, 453, 182, 201); } return list1; }
/** * This method returns jTextPane * * @return javax.swing.JTextPane */ private JTextPane getJTextPane() { if (jTextPane == null) { jTextPane = new JTextPane(); jTextPane.setContentType("text/html"); } return jTextPane; }
/** * This method returns jButton * * @return javax.swing.JButton */ private JButton getJButton() { if (jButton == null) { jButton = new JButton(); jButton.setText("Get Abstracts"); jButton.setBounds(440, 19, 164, 28);
} return jButton; }
/** * This method returns jList * * @return java.swt.List */ private JList getList() { if (list == null) { list = new JList(); list.setBounds(11, 200, 182, 215); } return list; }
/** * This method returns jScrollPane * * @return javax.swing.JScrollPane */ private JScrollPane getJScrollPane() { if (jScrollPane == null) { jScrollPane = new JScrollPane(); jScrollPane.setBounds(212, 70, 770, 585); jScrollPane.setViewportView(getJTextPane()); } return jScrollPane; }
private static void createAndShowGUI() {
//Create and set up the window. JFrame frame = new JFrame("Assistant"); frame.setDefaultLookAndFeelDecorated(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//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(); } }); } } Thanks, L
IchBin - 16 Mar 2006 05:55 GMT > Hi IchBin, > > I got your point.I made the changes as you suggested, but still on the > same path,. I think, iam missing something to add the Panel to JFrame. > could you please help me in this. [snip code] This will display your GUI.
You say you want to use a JTextArea so you define it give it no dimension and then add it to the pane. Then you load a JTextPane into a JScrollPane and display this.. No sure what you want? Also you should give your objects better names so it is easy to understand what they are for..Ex. 'label' could be 'Abstract_label', 'list' could be 'abstractList'.
import java.awt.Color; import java.awt.Dimension; import java.awt.Font;
import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextPane; import javax.swing.border.BevelBorder;
public class AssistantMyVersion { private JPanel pane = null; // private JTextArea jTextArea = null; private JButton jButton = null; private JList list = null; private JList list1 = null; private JTextPane jTextPane = null; private JScrollPane jScrollPane = null; private JLabel label = null; private JLabel label1 = null; private JLabel label2 = null;
public AssistantMyVersion() { createAndShowGUI(); } private void initialize() { pane = new JPanel(); pane.setLayout(null);
label = new JLabel("Abstracts: 0"); label.setBounds(154, 20, 171, 23); label1 = new JLabel("Abstracts returned: 0"); label1.setBounds(11, 173, 194, 23); label2 = new JLabel("Please enter query terms:"); label2.setBounds(11, 426, 196, 23);
// pane.add(getJTextArea()); pane.add(getList1()); pane.add(getJScrollPane()); pane.add(label); pane.add(label1); pane.add(getJButton()); pane.add(getList()); pane.add(label2); } /** * This method resets jList, jList1 and jTextPane * * @void */ private void reset() { list.removeAll(); list1.removeAll(); label1.setText("Please enter query terms: 0"); label2.setText("Abstracts returned: 0"); jTextPane.setText(""); } /** * This method set button enable or not * * @void */ public void setButtonEnable(boolean enable) { jButton.setEnabled(enable); } /** * This method add Abstracts to list * * @void */ public void addSequenceAbstracts() { label1.setText(" Abstracts returned: " + list.getModel().getSize()); } /** * This method returns jButton * * @return javax.swing.JButton */ private JButton getJButton() { jButton = new JButton(); jButton.setText("Get Abstracts"); jButton.setBounds(440, 19, 164, 28); return jButton; } /** * This method returns jList * * @return java.swt.List */ private JList getList() { list = new JList(); list.setBounds(11, 200, 182, 215); // add some 3D list.setBorder(BorderFactory.createBevelBorder( BevelBorder.LOWERED)); return list; } /** * This method returns list1 * * @return java.swt.List */ private JList getList1() { list1 = new JList(); list1.setBounds(12, 453, 182, 201); // add some 3D list1.setBorder(BorderFactory.createBevelBorder( BevelBorder.LOWERED)); return list1; } /** * This method returns jTextArea * * @return javax.swing.JTextArea */ // private JTextArea getJTextArea() // { // int rows = 20; // int cols = 30; // // int pos = 0; // jTextArea = new JTextArea("Initial Text", rows, cols); // jTextArea.insert("This text area display in any font",pos); // jTextArea.setFont(new Font("Serif", Font.ITALIC, 16)); // jTextArea.setLineWrap(true); // jTextArea.setWrapStyleWord(true); // jTextArea.setBackground(Color.blue); // // add some 3D // jTextArea.setBorder(BorderFactory.createBevelBorder( // BevelBorder.LOWERED)); // return jTextArea; // } /** * This method returns jTextPane * * @return javax.swing.JTextPane */ private JTextPane getJTextPane() { jTextPane = new JTextPane(); jTextPane.setContentType("text/html"); // add some 3D jTextPane.setBorder(BorderFactory.createBevelBorder( BevelBorder.LOWERED)); jTextPane.setBackground(Color.blue); return jTextPane; } /** * This method returns jScrollPane * * @return javax.swing.JScrollPane */ private JScrollPane getJScrollPane() { jScrollPane = new JScrollPane(); jScrollPane.setBounds(212, 70, 770, 585); jScrollPane.setViewportView(getJTextPane()); return jScrollPane; } private void createAndShowGUI() { // // Create and set up the window. JFrame frame = new JFrame("Assistant"); frame.setDefaultLookAndFeelDecorated(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // // Build the panel GUI Objects initialize(); // // Add GUI panel to frame frame.getContentPane().add(pane); // // frame needs some sise frame.setPreferredSize(new Dimension(1000, 700)); // // Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { new AssistantMyVersion(); } }
Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
L - 16 Mar 2006 16:09 GMT Hi IchBin,
Iam sorry, may be i confused you with my code. With your code i got the GUI with button, textarea and and 2 lists with labels, but didnot get the scrollpanel. but i expected my GUI in a slightly different way, 1. LABEL"Please enter your query terms" WITH TEXTAREA TO ENTER THE QUERY TERMS with AND or OR, 2. BUTTON[as the same way] 3. List with a label "Abstracts returned" [with a scroll pane(I didnot get the scrol pane)] 4. Textbox to display the whole "Abstract" from the "Abstracts returned" with a scroll pane.
I will work on that. Thank you so much for your help. please let me know if you have any suggestions
-L
IchBin - 16 Mar 2006 18:11 GMT > Hi IchBin, > > Iam sorry, may be i confused you with my code. With your code i got the > GUI with button, textarea and and 2 lists with labels, but didnot get YOU NEED TO NAME YOUR OBJECTS BETTER. YOU CAN NOT TELL WHAT A JLIST PURPOSE IS IF YOU NAME IT: LIST or LIST1 or LIST2.
This is for ALL your OBJECTS. You always code a program thinking about the next person who has to look at it to add new functionality or support it. If not just for pride in your code. Or, after coding it and then going out and getting drunk you can understand what the hell you wrote the next morning.
No - Their is no textArea loaded in a scroll pane. I commented it out. You had a JTextArea (not in a JScrollpane) AND A JTextPane within a JScrollpane added to your display pane.
You DO HAVE A JScrollpane, it does not display the scroll bars until they are needed! Just added text past the hoz. or dia. border... (OR LOOK AT YOUR CODE CLOSER)
> the scrollpanel. but i expected my GUI in a slightly different way, > 1. LABEL"Please enter your query terms" WITH TEXTAREA TO ENTER THE [quoted text clipped - 9 lines] > > -L No, what you see is what you defined. That is:
- Two JList's (Originally code had three Lists, none in a JScrollPane) - One Button - One JScrollPane loaded with a JTextPane - You defined your JTextArea (not in a JScrollPane) but failed to give it any dimension but added to pane anyway. So naturally you can not see it. I have no idea where you want to place it.
Just to let you know this is the "easy part". That is, coding you GUI. Now you have to write logic to do what you want it to do!
 Signature Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
L - 17 Mar 2006 04:12 GMT I totally understand what you are saying about. As a beginner this is a tough job for me, but i will try my level best. Also, iam glad that i got the GUI as i expected, one textfield, one button, 2 jLists with scrollpanes. Thanks for your advise. Honestly, -L
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|