Witam, skleciłem takie coś:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Menu window = new Menu();
window.setDefaultCloseOperation(Menu.EXIT_ON_CLOSE);
window.setSize(200 , 500);
window.setVisible(true);
}
//--------------------------------------------------------
//Definicja metod
static void zadanie_1()
{
...
}
static void zadanie_2()
{
...
}
...
static void zadanie_9()
{
...
}
static class Menu extends JFrame
{
// radiobuttony
private JRadioButton radio1 = new JRadioButton("Zadanie 1" , false);
private JRadioButton radio2 = new JRadioButton("Zadanie 2" , false);
private JRadioButton radio3 = new JRadioButton("Zadanie 3", false);
private JRadioButton radio4 = new JRadioButton("Zadanie 4" , false);
private JRadioButton radio5 = new JRadioButton("Zadanie 5" , false);
private JRadioButton radio6 = new JRadioButton("Zadanie 6", false);
private JRadioButton radio7 = new JRadioButton("Zadanie 7" , false);
private JRadioButton radio8 = new JRadioButton("Zadanie 8" , false);
private JRadioButton radio9 = new JRadioButton("Zadanie 9" , false);
private JRadioButton radio10 = new JRadioButton("Koniec" , false);
// przyciski
private JButton m_wykonaj = new JButton("Wybierz");
// konstruktor
public Menu()
{
// panel glowny
JPanel content = new JPanel();
content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
// dodawanie radiobuttonow do grupy
ButtonGroup bgroup = new ButtonGroup();
bgroup.add(radio1);
bgroup.add(radio2);
bgroup.add(radio3);
bgroup.add(radio4);
bgroup.add(radio5);
bgroup.add(radio6);
bgroup.add(radio7);
bgroup.add(radio8);
bgroup.add(radio9);
bgroup.add(radio10);
// dodawanie radiobuttonow do nowego panelu
JPanel radioPanel = new JPanel(new GridLayout(0, 1));
radioPanel.add(radio1);
radioPanel.add(radio2);
radioPanel.add(radio3);
radioPanel.add(radio4);
radioPanel.add(radio5);
radioPanel.add(radio6);
radioPanel.add(radio7);
radioPanel.add(radio8);
radioPanel.add(radio9);
radioPanel.add(radio10);
// ramka
radioPanel.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "Wybierz..."));
// tworzenie glownego panelu
content.add(radioPanel, BorderLayout.LINE_START);
content.add(m_wykonaj);
this.setContentPane(content);
this.pack();
// nasluch zdarzenia
m_wykonaj.addActionListener(new Wybor());
// tytul
this.setTitle("Labolatorium 1");
}
// nasluch zdarzenia
class Wybor implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// testowanie radiobuttonow
if (radio1.isSelected())
zadanie_1();
if (radio2.isSelected())
zadanie_2();
if (radio3.isSelected())
zadanie_3();
if (radio4.isSelected())
zadanie_4();
if (radio5.isSelected())
zadanie_5();
if (radio6.isSelected())
zadanie_6();
if (radio7.isSelected())
zadanie_7();
if(radio8.isSelected())
zadanie_8();
if (radio9.isSelected())
zadanie_9();
if (radio10.isSelected())
System.exit(0);
}
}
}
}
Robiłem to w NetBeans i śmiga. Jedak gdy chcę skompilować w JCretor to wywala w General Output :
java.lang.NoClassDefFoundError: Menu
Caused by: java.lang.ClassNotFoundException: Menu
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Menu. Program will exit.
Exception in thread "main"
Process completed.
Gdy usunę metody zadanie_x(); to działa, jednak same metody z zadaniami są poprawne (sterowanie zwykłym switch na JOptionPane.showInputDialog(); daje działający kod).
Pierwszy raz robie ręcznie coś na JFrame i JRadioButton i nie wiem czy to ja źle robie czy grymas JCreator ... W sumie z javy to raczkuje, więc nie wiem co tutaj może być nie tak.
Dodam ciekawą rzecz - jak zamienię kolejnością static class Menu exendes JFrame z metodami zadan to JCreator po kompilacji sypie na output :
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
Process completed.
Proszę o pomoc w doprowadzeniu tego kodu do używalności na JCreatorze.