Richard Craig - Research Engineer
 
 
By Richard Craig | Wednesday, 16th Mar, 2011 | | 0 Comments |

It’s finally time I got around to learning java. I’ve spent most of the past few years using Matlab and writing C or vb applications.

Here are some easy lead in and hello world examples for java.

import javax.swing.JOptionPane;
public class HelloWorldGUI {
public static void main(String[] args) {
System.out.print("Hello World");
JOptionPane.showMessageDialog( null, "Hello World!" );

}
}

This is a nice easy into to java programming as the universal ‘Hello World’ application helps demonstrate functionality with a minimum of code.

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

public class HelloWorldGUI2 {
private static class HelloWorldDisplay extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString( “Hello World!”, 20, 30 );
}
}
private static class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
public static void main(String[] args) {
HelloWorldDisplay displayPanel = new HelloWorldDisplay();
JButton okButton = new JButton(“OK”);
ButtonHandler listener = new ButtonHandler();
okButton.addActionListener(listener);

JPanel content = new JPanel();
content.setLayout(new BorderLayout());
content.add(displayPanel, BorderLayout.CENTER);
content.add(okButton, BorderLayout.SOUTH);

JFrame window = new JFrame(“Hello World”);
window.setContentPane(content);
window.setSize(250,100);
window.setLocation(100,100);
window.setVisible(true);
}

}

Similar Code Posts

Business Rules of Play

While reading about Peter R. Scholtes, I came across the Kelly Allen Associates website and their listed ‘Rules of Play’ page. Many of the rules of business are simple and obvious, yet are easy to overlook or break.

Read more...

Potential scale for EngD stakeholders

I’ve been thinking about a nice, quick and easy scale to base value decisions against a (potential) stakeholder’s relationship to the research project.

Read more...

Lean Working

I’m sure I’m not the only one who sometimes gets overloaded with work to be done. It can feel like waves of stress to get things done, trying to progress multiple jobs that just seem to hang around. After reading some more on LEAN principles again recently, I thought I’d give the LEAN approach to [...]

Read more...

.

.