L
learner9
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
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