Minggu, 12 Juni 2011

JTable as Spreadsheet - The Outline

Developing a spreadsheet in JTable can be done in these steps:
  1. Prepare a data structure to hold the formula and the value; Linked List preferred.
  2. Prepare a JTable to display the data structure prepared.
  3. Create a module so that whenever there are changes in JTable, the data structure is automatically synchronized.

JTable displays data by interpreting TableModel. It is easily achieved by setting the model of the JTable with the object of DefaultTableModel. This DefaultTableModel can also be configured to detect any changes happened to the model. Thus, any addition of the data in the model can be detected for later be added into the data structure. Refer to the listing below:

DefaultTableModel model = new DefaultTableModel();
model.addColumn("A");
model.addColumn("B");
model.addColumn("C");
model.setNumRows(10);
model.addTableModelListener(new TableModelListener() {
  public void tableChanged(TableModelEvent e) {
    DefaultTableModel modelAsal=(DefaultTableModel)e.getSource();
    int baris = e.getFirstRow();
    int kolom = e.getColumn();
    System.out.println(modelAsal.getValueAt(baris, kolom));
  }
});
jTable1.setModel(model);

addTableModelListener is a method to add TableModelListener event to detect any data changes. The data can then be obtained by first getting the model by using the e.getSource() to get the data specified by baris and kolom variable. The data obtained can then be added or manipulated as needed.

This explanation is a supplement for Data Structure 2010/2011 project in Sekolah Tinggi Teknik Surabaya.

Kamis, 21 April 2011

MDF in Microsoft Visual Studio 2010

MDF is a file which is used by SQL Server to save its data. It can be found in your SQL Server installation folder, whether it's express or not. But be careful, the MDF files should always with the LDF files in order for it to work.

Connecting to an MDF file to Microsoft Visual Studio 2010, can be done through Server Explorer. Look at the exhibit below.


Then, you have to choose Microsoft SQL Server Database File in Change Data Source dialog.

If you're facing the exhibit below, just point your mouse to Change button and change the data source.

At last, browse for the MDF file you want to connect.

Voila! The MDF file can then be read for your application.

ps: To be able to edit the content of the MDF files, you should put the files in unrestricted folder (a folder which has the priviledge to read, write, or modify).

Minggu, 21 Februari 2010

Indonesia merdeka

What makes a leader is called a leader?
Indonesia had lots of brave leaders in the past 55 years. Some became president, while some remained hidden under the surface of politics' shadow. Some behaved truthful while some stayed in a safe region.

The first breakthrough came from Ir. Soekarno and Moh. Hatta as the representatives of Bangsa Indonesia. They held the country for the first time and managed to get Indonesia into it's freedom. People cheered, and the excitement of freedom aroused all over the country, feeling free for the first time, after hundreds of years. The spirit to build Indonesia into a great country, to have the right to live well, to be human, and happy...

Well, it was. The freedom might have lead Bangsa Indonesia into a selfish moral. More people started to live as they want as long as they can live in wealth and power. Yes, wealth and power. This behavior can be seen from the tricky and gruesome politics which was held by those people in power. What were they after? Wealth and power.

The first man that I adore and I worship, Abdurrahman Wahid a.k.a Gus Dur, put such great changes for Bangsa Indonesia. Every odd policy was replaced or erased. New wise policies were added. He opened the layer that had been hidden for years; the layer that made Bangsa Indonesia living in blindness; the layer that degenerated Bangsa Indonesia for years... Shame, those people in power took him down through the people.

Will Indonesia stay like this forever? Living in a life, full of lie, trick, and bad politics?
Will Indonesia move on a next stage of its freedom?
It's all depend on us, Bangsa Indonesia. Whether we want to make this country great, or using this country only as the field of gold. Really, it's all depend on us.