Rabu, 11 Juli 2012

Membuat tabel menggunakan JAVA


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class DemoTable {  
  public JTable table;
  public JScrollPane scroller;
           
  public DemoTable() {     
        //Pembuatan Nama kolom
    final String[] judulKolom =
       {"No.", "Nama Tim", "Asal Negara", "Poin"};
    //mengisi data di tabel
    final Object[][] data = {
        {"1", "Barefoot", "Hongkong", "1661"},
        {"2", "Deimon Devilbats", "Japan", "1558"},
        {"3", "Oujo White Knight","Japan", "1450"},
        {"4", "NASA Allien", "USA", "1349"},
        {"5", "Russian Mammouth", "Rusia", "1346"},
        {"6", "Savanah Africa", "South Africa", "1241"},
        {"7", "The Name of Devil", "Hongkong", "1137"},
        {"8", "Dragon Team", "Singapore", "1038"},
        {"9", "Catalunia", "Spain", "1035"},
        {"10", "Sao Paolo", "Brazil", "930"},
        {"11", "Shinryuuji Naga", "Japan", "929"},
        {"12", "Sand Eagles", "Germany", "827"},
        {"13", "Yin Yang Scorpio","China", "824"},
        {"14", "Sonic Bats", "Spain", "723"},
        {"15", "Gold Tiger", "France", "720"}
    };
       
    table = new JTable(data, judulKolom);
               
    scroller = new JScrollPane(table,
       ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
       ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroller.setLocation(0,0);
    scroller.setSize(new Dimension(440, 300));     
  }
       
  public void createAndShowGUI() {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("Tabel Peringkat Klub Dunia");
    frame.setLayout(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
    frame.getContentPane().add(scroller);
               
    frame.setBounds(0, 0, 450, 350);
    frame.setLocationRelativeTo(null);

    frame.setVisible(true);
  }
   
  public static void main(String[] args) {     
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        DemoTable app = new DemoTable();
        app.createAndShowGUI();
      }
    });    
  }
}

1 komentar: