HI All,
hab langer nichts mahr mit Java gemacht und es ist so ziemlich alles was ich gelernt habe futsch, daher ist in meinem Code wahrscheinlich nur ein kleiner Grundlegender fehler.
Ich habe ein Fenster mit zwei Knöpfen, einen zum beenden und mit dem Zweiten soll die Funkion "Channel" ausgeführt werden. Allerdings bekomme ich den fehler "Channel cannot be resolved or is not a type".
Hier mein Code:
Danke im Voraus!
hab langer nichts mahr mit Java gemacht und es ist so ziemlich alles was ich gelernt habe futsch, daher ist in meinem Code wahrscheinlich nur ein kleiner Grundlegender fehler.
Ich habe ein Fenster mit zwei Knöpfen, einen zum beenden und mit dem Zweiten soll die Funkion "Channel" ausgeführt werden. Allerdings bekomme ich den fehler "Channel cannot be resolved or is not a type".
Hier mein Code:
Code:
import javax.swing.*; // Swing 1.1 or 1.2 required
import java.awt.*;
import java.awt.event.*;
public class HelloWorld implements ActionListener {
JTextArea area = new JTextArea();
JScrollPane scroll = new JScrollPane();
JPanel pane = new JPanel();
JButton buttonCancel = new JButton();
JButton buttonChannels= new JButton();
JFrame frame = new JFrame("CS Relax Server");
// Class config
String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
int nrChannels = 4;
public HelloWorld(int locationX, int locationY){
try{
UIManager.setLookAndFeel(lookAndFeel);
}
catch(Exception e){}
area = new JTextArea(13,50);
scroll.add(area);
scroll.getViewport().setView(area);
// Button Cancle
buttonCancel = new JButton("Cancel");
buttonCancel.addActionListener(this);
buttonCancel.setMaximumSize(new Dimension(100, 25));
buttonCancel.setSize(new Dimension(200, 25));
// Button Open Chanels
buttonChannels = new JButton("Open Channels");
buttonChannels.addActionListener(this);
buttonChannels.setMaximumSize(new Dimension(100, 25));
buttonChannels.setSize(new Dimension(200, 25));
// Put space between top-level container and its contents
pane = new JPanel();
pane.setBackground(new Color(0, 0, 0));
pane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
// pane.setLayout(new GridLayout(2, 1));
pane.setLayout(null);
pane.add(scroll);
pane.add(buttonCancel);
pane.add(buttonChannels);
buttonCancel.setLocation(0, 500);
buttonChannels.setLocation(10, 520);
frame.getContentPane().add(pane);
// Location and size options
frame.setSize(new Dimension(450,350));
frame.setLocation(locationX,locationY);
scroll.setLocation(0,0);
scroll.setSize(frame.getWidth()-8, frame.getHeight() - 60);
buttonCancel.setLocation(0, frame.getHeight() - buttonCancel.getHeight() * 2 -2);
frame.setVisible(true);
//Create a WindowListener to terminate the program
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
area.append("Beenden-Anforderung...\n");
frame = null;
System.gc();
System.exit(0);
}
}
);
} // end: public HelloWorld()
public void Channel(int locationX, int locationY){
System.out.println("Test X:"+locationX+" Y:"+locationY);
} // end: public void Channel()
public void actionPerformed(ActionEvent event)
{
String whichButton = event.getActionCommand();
if (whichButton.equals("Cancel")){
System.exit(0);
}
if (whichButton.equals("Open Channels")){
for (int i=1; i<=nrChannels; i++){
HelloWorld channel = new Channel(10+(30*i),100+(30*i));
}
}
}
public static final void main(String[] args) throws Exception {
HelloWorld helloWorld = new HelloWorld(10,100);
}
}
Danke im Voraus!