JAVA图形用户界面-“;找不到符号“;面板上的错误&引用;类、接口或枚举应为“;在…上
我正要完成GUI,这时我意识到我到处都有错误,在那之前,一切都很好。 当我尝试调用另一个面板时,出现错误“找不到符号”:JAVA图形用户界面-“;找不到符号“;面板上的错误&引用;类、接口或枚举应为“;在…上,java,user-interface,Java,User Interface,我正要完成GUI,这时我意识到我到处都有错误,在那之前,一切都很好。 当我尝试调用另一个面板时,出现错误“找不到符号”: this.setContentPane(servicios); 以及对象方法和某些“}”上的错误“需要类、接口或枚举”: text.setText(text.getText()+“\nInternet 20 mbps=$1199”) 我找不到任何看起来不对劲的东西 这是来自控制台的错误: 线程“main”java.lang.VerifyError中出现异常:构造函数必须调用
this.setContentPane(servicios);
以及对象方法和某些“}”上的错误“需要类、接口或枚举”:
text.setText(text.getText()+“\nInternet 20 mbps=$1199”)
我找不到任何看起来不对劲的东西
这是来自控制台的错误:
线程“main”java.lang.VerifyError中出现异常:构造函数必须调用super()或this(),然后才能在偏移量0处返回方法sistema.Principal.()V
位于sistema.sistema.main(sistema.java:18)
Java结果:1
代码如下:
Jframe:
public class Principal extends javax.swing.JFrame {
float total, x1=0, x2=0, x3=0;
total=total+x1+x2+x3;
/**
* Creates new form Principal
*/
public Principal() {
initComponents();
}
private void b1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.setContentPane(servicios);
validate();
}
private void b2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.setContentPane(productos);
validate();
}
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(c1.isSelected());
{
x1=199;
text.setText(text.getText()+"\nInternet 2 mbps = $199");
}
if(c2.isSelected());
{
x1=399;
text.setText(text.getText()+"\nInternet 5 mbps = $399");
}
if(c3.isSelected());
{
x1=699;
text.setText(text.getText()+"\nInternet 10 mbps = $699");
}
if(c4.isSelected());
{
x1=1199;
text.setText(text.getText()+"\nInternet 20 mbps = $1199");
}
else{
ms1.setText("Para agregar al carrito\nselecciona una opcion");
}
}
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(c5.isSelected());
{
x2=99;
text.setText(text.getText()+"\n100 llamadas nacionales = $99");
}
if(c6.isSelected());
{
x2=299;
text.setText(text.getText()+"\nLlamadas nacionales ilimitadas = $299");
}
if(c7.isSelected());
{
x2=359;
text.setText(text.getText()+"\n50 minutos larga distancia = $359");
}
if(c8.isSelected());
{
x2=999;
text.setText(text.getText()+"\nTelefonía ilimitada = $999");
}
else{
ms2.setText("Para agregar a carrito\nselecciona una opcion");
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(WIDTH);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
setContentPane(jPanel1);
revalidate();
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
t1.setText("Total = $"+total);
setContentPane(carrito);
revalidate();
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(WIDTH);
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
setContentPane(jPanel1);
revalidate();
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
setContentPane(salida);
revalidate();
}
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
x3=x3+5670;
text.setText(text.getText()+"\nComputadora DELL = $5,670");
}
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
x3=x3+8450;
text.setText(text.getText()+"\nLaptop DELL = $8,450");
}
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
x3=x3+11780;
text.setText(text.getText()+"\nLaptop SONY = $11,870");
}
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
x3=x3+1200;
text.setText(text.getText()+"\nMódem 2WIRE = $1,200");
}
private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
x3=x3+5700;
text.setText(text.getText()+"\nTelevision LCD = $5,700");
}
private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
x3=x3+4500;
text.setText(text.getText()+"\nConsola Xbox 360 = $4,500");
}
private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(WIDTH);
}
private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
setContentPane(jPanel1);
revalidate();
}
private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
t1.setText("Total = $"+total);
setContentPane(carrito);
revalidate();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Principal().setVisible(true);
}
});
}
private javax.swing.JButton b1;
private javax.swing.JButton b2;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.JCheckBox c1;
private javax.swing.JCheckBox c2;
private javax.swing.JCheckBox c3;
private javax.swing.JCheckBox c4;
private javax.swing.JCheckBox c5;
private javax.swing.JCheckBox c6;
private javax.swing.JCheckBox c7;
private javax.swing.JCheckBox c8;
private javax.swing.JPanel carrito;
private javax.swing.JLabel icon;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton12;
private javax.swing.JButton jButton13;
private javax.swing.JButton jButton14;
private javax.swing.JButton jButton15;
private javax.swing.JButton jButton16;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JScrollPane jScrollPane6;
private javax.swing.JScrollPane jScrollPane7;
private javax.swing.JScrollPane jScrollPane8;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
private javax.swing.JTextArea jTextArea3;
private javax.swing.JTextArea jTextArea4;
private javax.swing.JTextArea jTextArea5;
private javax.swing.JTextArea jTextArea6;
private javax.swing.JTextArea jTextArea7;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JToggleButton jToggleButton1;
private javax.swing.JLabel jlabel3;
private javax.swing.JLabel l1;
private javax.swing.JLabel l2;
private javax.swing.JLabel ms1;
private javax.swing.JLabel ms2;
private javax.swing.JLabel p1;
private javax.swing.JLabel p2;
private javax.swing.JLabel p3;
private javax.swing.JLabel p4;
private javax.swing.JLabel p5;
private javax.swing.JLabel p6;
private javax.swing.JPanel productos;
private javax.swing.JPanel salida;
private javax.swing.JPanel servicios;
private javax.swing.JTextArea text;
private javax.swing.JLabel ts1;
主要类别:
package sistema;
/** * * @author David */ public class Sistema {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Principal a = new Principal();
a.setVisible(true);
a.setLocationRelativeTo(null);
}
}
很多错误
首先,为什么每个if语句后面都有分号(;)。把那些拿走
您在课程结束时缺少一个结束语}
其中是initComponents()
method
编辑:看起来您使用GUI编辑器创建了GUI。我可能看不到initComponents()
您在哪里使用私有javax.swing.JLabel ts1代码>。
它应该是
private javax.swing.JTextArea t1代码>?重新启动IDE了吗?如果看不到更多的代码,很难判断,从我们这里看到的,似乎您还没有定义文本。据我所知,这些行看起来不错。不过,我怀疑直接在所述线条上方的线条看起来可能不太好。猜测一下,您可能有未配对的括号或圆括号,可能还有其他语法错误。请检查{
s和}
x的匹配情况。使用IDE的自动格式化,以便通过缩进查看它。IDE中的大括号等。对不起,已经用代码更新了。我搜索了语法错误,但什么也找不到。Text是一个textfield,我认为每次调用revalidate()
都应该是调用validate()
revalidate()
不作为方法存在。它是“}”!我检查了每个“}”,显然所有的都关闭了。固定的;如果是的话,我不知道我为什么这么做。谢谢你提供的validate()提示,我会更改它。至于“privatejavax…”我不知道,我正在使用netbeans,变量是自动完成的。initComponents()在我的变量声明下。公共主体(){initComponents();}