Java標準低速GUI 6 AWT/Swingat TECH
Java標準低速GUI 6 AWT/Swing - 暇つぶし2ch244:デフォルトの名無しさん
07/11/02 03:04:48
public class Practice extends JFrame {
 JPanel labelsPanel;
 public Practice (){
  JButton appendLabelButton = new JButton ("ラベルを追加");
  appendLabelButton.addActionListener (new ActionListener(){
   public void actionPerformed(ActionEvent event){appendLabel();}});
  JPanel buttonPanel = new JPanel();
  buttonPanel.setLayout(new FlowLayout());
  buttonPanel.add(appendLabelButton);
  labelsPanel = new JPanel();
  labelsPanel.setLayout(new FlowLayout());
  labelsPanel.setPreferredSize(new Dimension(400, 400));
  add(buttonPanel, BorderLayout.NORTH);
  add(labelsPanel, BorderLayout.CENTER);
 }
 void appendLabel(){
  JLabel helloLabel = new JLabel ("Hello");
  helloLabel.setBorder(BorderFactory.createLineBorder(Color.white, 1));
  helloLabel.setHorizontalAlignment(JLabel.CENTER);
  helloLabel.setPreferredSize(new Dimension(80,30));
  labelsPanel.add(helloLabel);
  labelsPanel.revalidate();
 }
 public static void main (String[]args){
  SwingUtilities.invokeLater(new Runnable(){
   public void run(){
    Practice frame = new Practice ();
    frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    frame.pack();frame.setVisible(true);
   }
  });
 }}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch