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
Roedy Green - 15 Mar 2006 06:14 GMT
>public class Assistant extends Jpanel {
You meant JPanel. How come the compiler did not complain?

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 15 Mar 2006 06:15 GMT
>public static Assistant getInstance() {
> if (m_instance == null)
> m_instance = new Assistant();
> return m_instance;
> }
You have gone to effort to make your panel a singleton. Any reason for
that?

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 15 Mar 2006 06:20 GMT
> this.add(getList2(), null);
there is no method getList2.
Fix whatever obvious errors you can. Don't worry about the weird ones.
Often they go away mysteriously when you fix the obvious errors. The
chain of causality is too complicated to bother worrying about.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 15 Mar 2006 06:21 GMT
> list2.removeAll();
there is no such thing as list2.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 15 Mar 2006 06:23 GMT
> list.add(abstracts);
there is no such variable as abstracts.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 15 Mar 2006 06:24 GMT
>textArea.setFont(new Font("Serif", Font.ITALIC, 16));
you forgot to import java.awt.Font;

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 15 Mar 2006 06:25 GMT
> 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);
There is no textArea variable. I think you meant to say jTextArea.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 15 Mar 2006 06:26 GMT
>Assistant.java:221: 'class' or 'interface' expected
> private static void createAndShowGUI() {
When you clean all those other errors up, this one will go away.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Luc The Perverse - 15 Mar 2006 07:17 GMT
>>Assistant.java:221: 'class' or 'interface' expected
>> private static void createAndShowGUI() {
>
> When you clean all those other errors up, this one will go away.
ROFL
Unique reply . . . um . . .strategy
--
LTP
:)
learner9@gmail.com - 15 Mar 2006 14:38 GMT
learner9@gmail.com - 15 Mar 2006 14:38 GMT
Roedy Green - 15 Mar 2006 20:53 GMT
On Tue, 14 Mar 2006 23:17:12 -0700, "Luc The Perverse"
<sll_noSpamlicious_z_XXX_m@cc.usu.edu> wrote, quoted or indirectly
quoted someone who said :
>>>Assistant.java:221: 'class' or 'interface' expected
>>> private static void createAndShowGUI() {
>>
>> When you clean all those other errors up, this one will go away.
>
>ROFL
I am not kidding. That is often true and in this case is definitely
true since I did it. Clean up the errors you do understand and the
downstream complex effects of those errors go away.
So long as you can solve even one error, you can recompile and have a
shot at others disappearing further simplifying your task.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
steve - 18 Mar 2006 12:00 GMT
>> Assistant.java:221: 'class' or 'interface' expected
>> private static void createAndShowGUI() {
>
> When you clean all those other errors up, this one will go away.
roedy , can you stop doing this !!!
A single post is all that is required.
it is lame, just so you can improve your posting average.
Steve

Signature
http://NewsGuy.com/overview.htm 30Gb $9.95 Carry Forward and On Demand Bandwidth
Roedy Green - 18 Mar 2006 17:45 GMT
>roedy , can you stop doing this !!!
>
>A single post is all that is required.
>it is lame, just so you can improve your posting average.
I believe that a reply should try to stick to as narrow a topic as
possible. I detest threads that attempt to track several independent
conversations at once. Each idea should get its own thread.
The other end of the spectrum are threads where everything that has
ever been said about anything is quoted with 2 lines of additional
information. PHHT. I want to read an entire post in one screen with
one keystroke. In fact often, if the person can't get to the point in
the first screen, I say screw 'em and read something else.
The tighter the focus of a post the more likely Google can home in on
it without all the extraneous distractions to its search.
I admit that string was going overboard the other direction. I just
kept finding one more error.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.