• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

xcom98@chollian.net

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: 218
VI Editor Ruby Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I read your code correctly, it seems that you
defined your actionPerformed function INSIDE your constructor.
You need to move it outside of the constructor.
That's why you got 2 messages:
1. illegal declaration for you declare method
inside the constructor
2. Now the compiler can't find your actionPerformed()
as expected and demand your class be abstract.
 
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, Ryo Saeba !
But, after I move actionPerformed() method to outside Constructor, I got the following error.
Is it caused by illegal definition of JTable ?

============================================
Error Message
============================================
C:\Selection>javac Selection.java
Selection.java:120: cannot resolve symbol
symbol : constructor JTable (java.lang.Object,java.lang.String[])
location: class javax.swing.JTable
jTable1 = new JTable(data1[0][to], columnNames);
^
Selection.java:124: cannot resolve symbol
symbol : constructor JTable (java.lang.Object,java.lang.String[])
location: class javax.swing.JTable
jTable1 = new JTable(data2[0][to], columnNames);
^
2 errors
============================================
 
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, Ryo Saeba !
But, after I move actionPerformed() method to outside Constructor, I got the following error.
Is it caused by illegal definition of JTable ?

============================================
Error Message
============================================
C:\Selection>javac Selection.java
Selection.java:120: cannot resolve symbol
symbol : constructor JTable (java.lang.Object,java.lang.String[])
location: class javax.swing.JTable
jTable1 = new JTable(data1[0][to], columnNames);
^
Selection.java:124: cannot resolve symbol
symbol : constructor JTable (java.lang.Object,java.lang.String[])
location: class javax.swing.JTable
jTable1 = new JTable(data2[0][to], columnNames);
^
2 errors
============================================
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


symbol : constructor JTable (java.lang.Object,java.lang.String[])
location: class javax.swing.JTable
jTable1 = new JTable(data2[0][to], columnNames);


data2[0][to] refers to a object at row 0, col to.
However, the JTable constructor expects an 2-D array, not an Object.
It should be like this:

kawaii
 
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
After seeing Graeme Brown' help
with this,
I modified my code as follows.

But, It also generate following error which seems
inappropriate Casting of ComboBox and Object.
=================================================
C:\Selection>javac Selection.java
Selection.java:98: Incompatible type for method. Explicit cast needed to convert
Selection to java.awt.event.ActionListener.
jComboBox1.addActionListener(this);
^
Selection.java:99: Incompatible type for method. Explicit cast needed to convert
Selection to java.awt.event.ActionListener.
jComboBox2.addActionListener(this);
^
Selection.java:100: Incompatible type for method. Explicit cast needed to conver
t Selection to java.awt.event.ActionListener.
jComboBox3.addActionListener(this);
^
Selection.java:115: Incompatible type for array. Explicit cast needed to convert
java.lang.Object to java.lang.Object[].
Object[][] data11 = {data1[0][to]};
^
Selection.java:120: Incompatible type for array. Explicit cast needed to convert
java.lang.Object to java.lang.Object[].
Object[][] data22 = {data2[0][to]};
^
5 errors
=================================================
Can anyone help me ?
Please ~~
 
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 post image file which contain 3-JComboBox &
1-JTable for your reference.
I want display just a record in all-table record
which is searched by 3-JComboBox.

Thanks for your interest.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i tried ur code and was able to compile with out errors.. try to check it out.
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 = {"Name",
"Power",
"watts",
"Qty",
"TOR",
"Rate",
"운전용접촉기",
"Code",
"�",
"$"};
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("Power Example");
jLabel1.setText("Name");
jLabel2.setText("Frequency");
jLabel3.setText("Watts");
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, columnNames);
}
if(jComboBox2.getSelectedIndex() == 1){
to = 3* (jComboBox3.getSelectedIndex()) + jComboBox1.getSelectedIndex();
jTable1 = new JTable(data2, 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();
}
}

}
 
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 Rajendar for your concerns !
It's seems that you modified code mainly at two
point.
1. add "implements ActionListener"
2. move

from Constructor to actionPerformed().
I compiled and run it, but did not displayed
any table-record. I think it caused by misunderstand of code variables and you did not use "int to" variable. So I should explain my purpose more detail.
In the above image file from left to right,
first ComboBox check whether to read data1 or data2 and Second ComboBox use getSelectedIndex() to multiply by 3.
And final Third ComboBox use getSelectedIndex() to get a index.
By using these index, calculate "int to" variable,
make 2-D array {data1[0][to]},{data2[0][to]} and put it into data11, data22 respectively.
With your help, I modified my code as follows ;


But it also return following errors.
============================================
C:\Selection>javac Selection.java
Selection.java:103: Incompatible type for array. Explicit cast needed to convert
java.lang.Object to java.lang.Object[].
Object[][] data11 = {data1[0][to]};
^
Selection.java:109: Incompatible type for array. Explicit cast needed to convert
java.lang.Object to java.lang.Object[].
Object[][] data22 = {data2[0][to]};
^
2 errors
============================================
I wonder if it really about Casting problem.
How can I overcome these difficulty ?
 
reply
    Bookmark Topic Watch Topic
  • New Topic