ahojte, potreboval by som pomoc.. robim taku appku a stale mam problem s urcitym typom situacie.
Napisal som iba taky ilustracny kod, ktory tuto situaciu ukazuje. Toto je len velmi jednoduche.. po stlaceny tlacidla "add text" by sa malo do JPanel p2 nacitat text "hi".. uz som toho skusal strasne vela, no nedari sa mi, preto vas chcem poprosit ci by ste sa mi na to nepozreli a nedali nejake napady.. pisal som to v netbeans
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;/**
*
* @author simon
*/
public class What {private JPanel p1;
private JPanel p2;
private Container pane;
public What(){
JFrame frame = new JFrame("app");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
start(frame.getContentPane());
frame.setPreferredSize(new Dimension(300, 300));
frame.pack();
frame.setVisible(true);
}
public void start(Container pane){
this.pane = pane;
pane.setLayout(new BorderLayout());
p1 = new JPanel();
p2 = new JPanel();
p1.setSize(new Dimension(200, 100));
p1.setBorder(new CompoundBorder(new TitledBorder("JPanel 1"), new EmptyBorder(3,3,3,3)));
p1.setLayout(new BorderLayout());
JButton ok = new JButton("add text");
ok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addText();
}
});
p1.add(ok);
p2.setSize(new Dimension(300, 200));
p2.setBorder(new CompoundBorder(new TitledBorder("JPanel 2"), new EmptyBorder(3,3,3,3)));
p2.add(new JLabel("hello"), BorderLayout.NORTH);
pane.add(p1, BorderLayout.NORTH);
pane.add(p2, BorderLayout.CENTER);
}
public void addText(){
p2.add(new JLabel("hi"), BorderLayout.SOUTH);
p2.repaint();
}
public static void main(String[] args) {
new What();
}
}