• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How can I debug it ?

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My swing design is composed with 3-ComboBox & JTable.
I want search specific Table record which correspond to JComboBox
value. After I compile Selection.java file,
I got the following error message.
Can anyone help me to solve this problem ?

My e-mail address is

[email protected]

Thanks for reading !!
================================================================================
Selection.java
================================================================================
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;

/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/
public class Selection extends JFrame implements ActionListener {

int to;

JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JScrollPane jScrollPane1 = new JScrollPane();

JTable jTable1;

Object[][] data1 = {
{"440", "GMC-3000", "300", "GTH-600", "400-600", "GMC-150", "GMC-300", "ABS803a", "800", "200"},
{"220", "GMC-150", "150", "GTH-220", "160-240", "GMC-100", "GMC-150", "ABS403a", "400", "100"},
{"165", "GMC-150", "140", "GTH-220", "120-180", "GMC-85", "GMC-150", "ABS403a", "300", "100"},
{"528", "GMC-400", "400", "GTH-600", "400-600", "GMC-220", "GMC-400", "ABS1003a", "1000", "325"},
{"264", "GMC-180", "180", "GTH-400", "200-300", "GMC-100", "GMC-180", "ABS603a", "500", "150"},
{"198", "GMC-150", "140", "GTH-220", "160-240", "GMC-100", "GMC-150", "ABS403a", "350", "100"},

};

Object[][] data2 = {
{"440", "GMC-600", "600", "GTH-600", "400-600", "", "", "ABS803a", "800", "250"},
{"200", "GMC-220", "220", "GTH-220", "160-240", "", "", "ABS403a", "400", "150"},
{"176", "GMC-180", "180", "GTH-220", "160-240", "", "", "ABS403a", "350", "150"},
{"528", "GMS-600", "600", "GTH-600", "400-600", "", "", "ABS1003", "1000", "325"},
{"264", "GMS-300", "300", "GTH-400", "200-300", "", "", "ABS603a", "500", "200"},
{"211", "GMS-300", "250", "GTH-400", "200-300", "", "", "ABS403a", "400", "200"},
};
String[] columnNames = {"모터부하",
"전자접촉기",
"정격사용전류",
"과부하계전기",
"TOR설정",
"시동용접촉기",
"운전용접촉기",
"배선용차단기",
"정격전류",
"전선단면적"};
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();

String[] start = { "Y-Delta 기동", "직입기동"};
String[] voltage = { "200V~240V 3상 60 Hz", "380V~440V 3상 60 Hz","500V~550V 3상 60 Hz"};
String[] mt = { "110kW, 150HP", "132kW, 180HP"};
JComboBox jComboBox1 = new JComboBox(mt);
JComboBox jComboBox2 = new JComboBox(start);
JComboBox jComboBox3 = new JComboBox(voltage);



/**Construct the frame*/
public Selection() {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(800, 500));
this.setTitle("기종선정 프로그램");
jLabel1.setText("기동 조건");
jLabel2.setText("정격전압");
jLabel3.setText("모터출력");
jPanel1.add(jLabel1, null);
jPanel1.add(jComboBox2, null);
jPanel1.add(jLabel2, null);
jPanel1.add(jComboBox3, null);
jPanel1.add(jLabel3, null);
jPanel1.add(jComboBox1, null);
jPanel1.add(jScrollPane1, null);

contentPane.add(jPanel1, BorderLayout.NORTH);

jComboBox1.setSelectedIndex(0);
jComboBox2.setSelectedIndex(0);
jComboBox3.setSelectedIndex(0);

jComboBox1.addActionListener(this);
jComboBox2.addActionListener(this);
jComboBox3.addActionListener(this);
public void actionPerformed(ActionEvent e) {

if(jComboBox2.getSelectedIndex() == 0){
to = 3* (jComboBox3.getSelectedIndex()) + jComboBox1.getSelectedIndex();

jTable1 = new JTable(data1[0][to], columnNames);
}
if(jComboBox2.getSelectedIndex() == 1){
to = 3* (jComboBox3.getSelectedIndex()) + jComboBox1.getSelectedIndex();
jTable1 = new JTable(data2[0][to], columnNames);
}
}
jScrollPane1.getViewport().add(jTable1, null);
jTable1.setPreferredScrollableViewportSize(new Dimension(790, 300));



}

/**Main method*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Selection frame = new Selection();
frame.setVisible(true);
}
catch(Exception e) {
e.printStackTrace();
}
}

}

================================================================================

C:\Selection>javac Selection.java
Selection.java:106: illegal start of expression
public void actionPerformed(ActionEvent e) {
^
Selection.java:18: Selection should be declared abstract; it does not define act
ionPerformed(java.awt.event.ActionEvent) in Selection
public class Selection extends JFrame implements ActionListener {
^
2 errors
================================================================================
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um... the answer is right there.

Typically, when you see "illegal start of expression"... start looking for a misplaced brace - { or }

Start looking around line 106.

Still not sure? the next error, line 18. Your class hasn't implemented the actionPerformed method. But you think it has, because you've typed it. But wait, you start implementing the method at line 106. Hmm.. that's the first error. They must be related.

You are defining the implementation for actionPerformed while you are still inside the constructor.
[ February 27, 2002: Message edited by: Mike Curwen ]
 
SungChan Park
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your concern, Mike Curwen !

I counted { & } which amount to 26.
(It seems that there's no brace error.)
I've intentionally put actionPerformed method
inside Constructor, because I had seen many examples like this way.
Other Qusetion)

In the above method, I tried to read data1 or data2 by jComboBox2 and uesd getSelectedIndex()
method to count array (data[][])index.
I wonder if I successfully implemented.
Sincerely.
 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are mixing up two ways of implementing ActionListener. There are therefore two ways of fixing the problem:
1. Take actionPerformed method out of the constructor and make it an instance method.
Add a line "addActionListener(this);" to the constructor.
2. Implement the actionListener as an anonymous inner class.
Remove the "implements ActionListener" from the class definition and replace the actionListener method with
 
SungChan Park
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I modified my Selection.java file as follows.
in Swing/Awt Bulletin
But, still, trouble.
Please, help me !!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic