Hallo Leutz,
bin ein ziemlicher Neuling in Swing. Hab das Problem das der zweite Button ("Open Channels") nicht angezeigt wird.
Hier ist mein Code, kann mir jemand sagen wiran das liegt?
bin ein ziemlicher Neuling in Swing. Hab das Problem das der zweite Button ("Open Channels") nicht angezeigt wird.
Hier ist mein Code, kann mir jemand sagen wiran das liegt?
Code:
import javax.swing.*;
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 Channels
buttonChannels = new JButton("Open Chanels");
buttonChannels.addActionListener(this);
buttonChannels.setMaximumSize(new Dimension(10, 25));
buttonChannels.setSize(new Dimension(20, 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, scroll.getHeight());
frame.getContentPane().add(pane);
// Lokation 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);
}
}
);
}
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 helloWorld = new HelloWorld(10+(30*i),100+(30*i));
}
}
}
public static final void main(String[] args) throws Exception {
HelloWorld helloWorld = new HelloWorld(10,100);
}
}