Longtime no speak


It has been quite a while since I have posted here so I feel an update is in order. I have finished my 2nd year at University so have technically finished for the summer. However I have been given a research grant from EPRS so I am now working as a research associate in the Culture Lab of Newcastle University. In this past week I have learnt a lot of C++ and started to look at OpenGL. I needed to this as I am going to be working with the OpenCV library written in C++ (so I need to learn C++) and OpenGL is going to be used to produce some GUI for applications I am going to be making.

On another note, I am currently posting this blog using Firefox 3 Beta 5, which comes with the latest addition of Ubuntu, something that I have just installed moments ago so be expecting a review on this OS in the coming weeks. I just have to say that it is already better than Gutsy in my eyes as it has support for my wireless adaptor out the box and I have connected to the Internet with no problems compared to after installing Gutsy and having issues with IPv6.

I will leave it here for the moment but will be returning soon!

UPDATE: Things have changed slightly since my last post. I installed Vista after Ubuntu, which naturally overwrote the bootloader so I could not get back onto Ubuntu without reinstalling GRUB. Once this was done I had to change the menu.lst file so have I could select Vista.

Another point I would like to make is that unlike Hardy, Vista could not connect to the Internet using my wireless adaptor so I had to search the Internet for the correct drivers - oh the irony.


Interfaces SHOULD be your friend


I recently had to develop a web browser as part of my univeristy course as a practice of creating GUI’s in Java, as well as being able to create an easy to upgrade piece of software. We were strictly told to use interfaces in the creation of the program, but I did not really take in what they meant by this. So I went away and created an amazing web browser (for a basic web browser who’s design is not about support CSS or anything else) and only used interfaces for some of the main components of the web browser so if those components were to be replaced then there would at least be some way of ensuring that what they’re replaced with would allow the web browser to still work.

I got 96% for the web browser - pretty good ey? I have however just realised what the module leader meant when he said to use interfaces to improve deplugability. He meant you should use them in the declaration of get methods so that if you needed to change the get method so that it used a data type it would break the entire program and allow it all to function correctly.

Take the example below. The get method has been defined to use an ArrayList, nothing advanced (not even using generics!!).

1
2
3
4
5
6
7
8
public ArrayList getNames()
{
	ArrayList names = new ArrayList();
	names.add("tom");
	names.add("edd");
 
	return names;
}

Now imagine you didn’t want to use an ArrayList anymore, but rather a LinkedList. You may think that isn’t a problem, just need to change the method so that it uses a different type of List. Wrong - you will have to change everything that uses this method as it to will be using the type ArrayList.

Now imagine that you had declared this method to return the interface List and you wanted to change the type of List this method uses. You could change the data type within the method to watever you want it to be and as long as the method returned a data type of List then there should be no problems.

1
2
3
4
5
6
7
8
public List getNames()
{
	ArrayList names = new ArrayList();
	names.add("tom");
	names.add("edd");
 
	return names;
}

I hope this is enough reason for people to START USING INTERFACES. I for one will be trying to remember to use them all of the time to try and reduce this sort of issue occurring in the future.

(If you cared to know I lost the 1 mark on the web browser for not refreshing the web page correctly, something about not forcing it).


Bit of Java GUI


It’s coming to the end of the university holidays (well actually it isn’t, my term doesn’t start until October!!) and I felt as if I should at least look over some things I learnt in the previous year. (un)Fortunately I couldn’t be bothered and decided to start teaching myself something I want to do last year, program a GUI.

Now at first I thought this was rather difficult but in actual fact it isn’t. I am not as if an expert or anything or created a program which is rather brilliant or does any particular function but I have managed to create a menu bar and a button which actually do something. My hope is to build on this and be able to implement them more cleanly and effectively. Here is the code anyway.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class TestingButtons implements ActionListener
{
 
    private JFrame frame = new JFrame("Tom's Program");
    private JMenuBar menuBar;
    private JMenu fMenu, hMenu;
    private JMenuItem aItem, eItem, dItem;
    private JButton popBtn;
    private JLabel writing;
 
    public TestingButtons()
    {
        //menu
        menuBar = new JMenuBar();
        fMenu = new JMenu("File");
        hMenu = new JMenu("Help");
        eItem = new JMenuItem("Exit",'e'); //the e provides the alt+e shortcut
        aItem = new JMenuItem("About",'a'); 
        dItem = new JMenuItem("Does Nothing");
 
        //buttons
        popBtn = new JButton("Produces a pop-up");
        popBtn.addActionListener(this);
 
        //label
        writing = new JLabel("Click here");
    }
 
    public void actionPerformed(ActionEvent e)
    {
        String command = e.getActionCommand();
        if(command.equals("Exit"))
        {
            System.exit(0);
        }
        else if(command.equals("About"))
        {
            String title = "About";
            String description = "This program was created by Tom McKee as a test to say as to what would happen. If you are reading this then the about works fine";
            JOptionPane.showMessageDialog(null,description,title,JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {
            String title = "Greetings";
            String description = "Welcome to my first GUI program!!";
            JOptionPane.showMessageDialog(null,description,title,JOptionPane.INFORMATION_MESSAGE);
        }
    }
 
    public JMenuBar createMenuBar()
    {
        eItem.addActionListener(this);
        aItem.addActionListener(this);
 
        fMenu.add(dItem);
        fMenu.addSeparator();
        fMenu.add(eItem);
        hMenu.add(aItem);
        menuBar.add(fMenu);
        menuBar.add(hMenu);
        return menuBar;
    }
 
    public JFrame setupFrame()
    {
        frame.getContentPane().setLayout(new BorderLayout());
        frame.add(createMenuBar(),BorderLayout.NORTH);
        //frame.add(writing,BorderLayout.NORTH);
        frame.add(writing,BorderLayout.SOUTH);
        frame.getContentPane().add(popBtn,BorderLayout.CENTER);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
        return frame;
    }
 
    public static void main(String[] args)
    {
        TestingButtons test = new TestingButtons();
        test.setupFrame();
    }
}
 
 
Unfortunately the code block on this here word press is shit so I used block quotes all indentation has fucked off basically. Anyway just thought I would mention this and see if I could built on anything else. I suppose I should look over all those data storage things as well...