ورود

View Full Version : مبتدی: ارور در اجرای ایجاد پنجره



saeed51100
یک شنبه 27 اسفند 1396, 21:45 عصر
سلام
مثال صفحه 395 آقای جعفر نژاد قمی را عینا با نت بینز اجرا کرده و ارور می دهد . اشکال از کجاست ؟

//پنجره و استفاده از Jbutton و Jlabel


package test113;
import javax.swing.JFrame;


public class Test113 {


private static final int WIDTH=350;
private static final int HEIGHT=350;

public static void main (String[] args){
LabelsColorsFonts demoObject=new LabelsColorsFonts();
demoObject.setSize(WIDTH , HEIGHT);
demoObject.setVisible(true);
demoObject.setDefaultCloseOperation(JFrame.EXIT_ON _CLOSE);

}

}




//فایل جدیدLabelsColorsFonts


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;



public class LabelsColorsFonts extends JFrame{
private JLabel javaL , programmingL ;
private JButton colorB , fontB ;
private ColorButtonHandler cHandler ;
private FontButtonHandler fHandler ;
private Container pane ;

public LabelsColorsFonts(){
//Create two labels
javaL=new JLabel("Java",SwingConstants.CENTER);
programmingL=new JLabel("Programming",SwingConstants.CENTER);

//Create color button
colorB=new JButton("Color");
cHandler=new ColorButtonHandler();
colorB.addActionListener(cHandler);

//Create font button
fontB=new JButton("Font");
fHandler=new FontButtonHandler();
fontB.addActionListener(fHandler);

//Set the title of the window
setTitle("Labels , fonts , and colors demonstration");

//Get the container
pane=getContentPane();

//Set the layout
pane.setLayout(new GridLayout(2,2));

//Place the components in the pane
pane.add(javaL);
pane.add(programmingL);
pane.add(colorB);
pane.add(fontB);

}
//************************************************** *

private class ColorButtonHandler implements ActionListener{
@Override
public void actionPerformed(ActionEvent e){
javaL.setForeground(Color.red);
programmingL.setForeground(Color.blue);

pane.setBackground(Color.cyan);

colorB.setBackground(Color.orange);
fontB.setBackground(Color.orange);
}

}//end of class class ColorButtonHandler
//************************************************** *******
private class FontButtonHandler implements ActionListener{
@Override
public void actionPerformed(ActionEvent e){
javaL.setFont(new Font("Arial",Font.BOLD,24));
programmingL.setFont(new Font("Arial",Font.BOLD,24));

}
}//End of class FontHandler
}//End of class LabelsColorsFonts

vahid-p
سه شنبه 29 اسفند 1396, 13:42 عصر
خطا رو بنویسید

saeed51100
یک شنبه 05 فروردین 1397, 19:22 عصر
خطا رو بنویسید
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: test113.LabelsColorsFonts
at test113.Test113.main(Test113.java:14)
C:\Users\soroosh\AppData\Local\NetBeans\Cache\8.1\ executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)

vahid-p
دوشنبه 06 فروردین 1397, 01:38 صبح
شما در کلاس Test113 از LabelsColorsFonts استفاده کردید در صورتی که نه این کلاس رو import کردید و نه مشخصه در یک پکیج هستند (اگر در یک پکیج هستند نیازی به import نیست). در کلاس LabelsColorsFonts ابتدای کلاس package test113; رو نمیبینم.
هر چند اگر از ide استفاده کنید این خطاها رو بهتون میگه و به اینجا نمیرسه که بخواید کامپایل کنید و اجرا کنید و بعد خطا بگیرید.