Physical Prototyping: Final Project “The Mirror of Truth”

Saturday, March 31st, 2012

Explination of the project here

One of the oldest symbols of vanity still in use is the mirror. Snow White is a classic tale with a mirror that only tells the truth so we took that concept and turned it up a little bit. People put a lot of time and money to look. The first to condemn you in the morning or evening before you leave home is often yourself when you make the final touches in front of the mirror. So what happens if you are not the one who gives the opinion, but a real “mean machine”? We wanted to get people to think about all the time and money you put on their “image” really been worth it. To be pulled down to earth is a very humbling feeling that many people should experience more often.

We use arduino and proximity sensor to accomplish this project. The idea is that a person is in front of the mirror for an X amounth of time the mirror will insult that person.
You will need Arduino to control the proximity sensor and processing to control the audio.

Source CODE arduinofungerarnu:




/*
 * Pablo Suzarte
 * Fina project "Mean Machines"
 * Physicial Prototyping
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */
int sensorPin = 0;     // Analog input pin 
int sensorValue = 0;   // value read from the sensor
int check = 0;


long previousMillis = 0; 
long interval = 5000;  

void setup() {

  
  randomSeed(42);

 

  Serial.begin(9600);  // for debugging
}

void loop() {
  unsigned long currentMillis = millis();
  sensorValue = analogRead(sensorPin); // read the sensor value
  
//Serial.println(sensorValue);
  // the sensor actually gives results that aren't linear.
  // this formula converts the results to a linear range.
  int range = (6787 / (sensorValue ));
  
  if( range >10 && range<90 && check == 0) {
    delay(200);
    sensorValue = analogRead(sensorPin); // read the sensor value
    int range = (6787 / (sensorValue ));
    
    if( range >10 && range<90){
     
      previousMillis = currentMillis;
      check = 1;
      Serial.print('1'); 
      delay(5000);
    }
  }
  else if( range >10 && range<90 && check == 1 && (currentMillis - previousMillis > interval)) {
    previousMillis = currentMillis;
    check = 2;
    Serial.print('2');   
    delay(10000);
  }
  
  else if( range >10 && range<90 && check == 2 && (currentMillis - previousMillis > interval)) {
    previousMillis = currentMillis;
    check = 0;
    Serial.print('3');   
    delay(6000);
  }
 
  else if((range <10 && range > 0)|| range>90) check = 0;
  
  //Serial.println('3');
  //Serial.println(range);
  delay(200);
  
  //Serial.println(range, DEC);    // print the sensor value
//delay(1000);   

}




import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;

import cc.arduino.*;

long start, finished, elapsed; //variable for the timer
int counter, total; 
int desireTime = 1;
int desireTime2 = 5;
boolean check = false;

Minim minim;
AudioPlayer song;
AudioPlayer song2;
AudioPlayer s0;
AudioPlayer s1;
AudioPlayer s2;
AudioPlayer s3;
AudioPlayer s4;
int index = int (random(0, 2));

int beginTime = 0;
// Example by Tom Igoe

import processing.serial.*;

Serial myPort;    // The serial port
PFont myFont;     // The display font
String inString;  // Input string from serial port
char i;
int lf = 10;      // ASCII linefeed

void setup() {
  size(400, 200);
  minim = new Minim(this);
  s0 = minim.loadFile("damn.mp3");
  s1 = minim.loadFile ("now.mp3");
  s2 = minim.loadFile ("per.mp3");
 // s1= minim.loadFile ("cheer.mp3");
 // s2= minim.loadFile ("littleblackman.mp3");
 // s3 = minim.loadFile ("ParkBusFace.mp3");
 // s4 = minim.loadFile ("ratface.mp3");
  // Make your own font. It's fun!
  //  myFont = loadFont("AgencyFB-Reg-48.vlw");
  //  textFont(myFont, 18);
  // List all the available serial ports:
  println(Serial.list());

  // I know that the first port in the serial list on my mac
  // is always my  Keyspan adaptor, so I open Serial.list()[0].
  // Open whatever port is the one you're using.
  myPort = new Serial(this, "COM6", 9600);
  myPort.buffer(3);
}

void draw() {

    
  if ( myPort.available() > -1) {  // If data is available,
    
    i = myPort.readChar();         // read it and store it in val
    myPort.clear();
  }
  background(255);
  
  
  println(i);
  
      
  if (i == '1' ) {
    timer();
    
  }
//   if (beginTime>0&& millis()-beginTime> 500){
  
  //if (inString!= null)
    //i = Float.valueOf(inString).floatValue();
       
  if (i == '2') {
//      delay(3000);
    timer2();
//    check = false;
  }
  
  if (i == '3'){
    timer3();
  }
//  else if(i<20 && i>90){
//    check = false;
//  }
 

}

/*void serialEvent(Serial myPort) {
  inString = myPort.readString();
  println("värde"+inString);
}*/


void stop()
{
  song.close();
  minim.stop();

  super.stop();
}

void timer() {

  //start=millis();
//  delay(3000);
  counter++;

//  if (counter>=desireTime && song.isPlaying() == false) {

    //    for (int i=0;i<10;i++) {
    //      
    //    s[index].play();
    //    delay(9500);
    //    song.pause();
    //    song.rewind();
    //    
    //SKRATT
    s0.play();
    delay(8100);
    s0.pause();
    s0.rewind();
    delay(2000);
  
}


void timer2() {

  
  counter++;

//  if (counter>=desireTime2 && song.isPlaying() == false) {
    
  //CHEER
    s1.play();
    delay(6000);
    s1.pause();
    s1.rewind();
    delay(5000);

//    //BUSFACE
//    s3.play();
//    delay(2500);
//    s3.pause();
//    s3.rewind();
//    delay (3000);
}

void timer3(){
  counter++;
    //Littleman
   s2.play();
   delay(9100);
   s2.pause();
   s2.rewind();
  
}



Zip File with all the files

Proximity Sensor:

Final Product:

Video!

Physical Prototyping: assignment 3 “Hydro Coaster”

Friday, March 30th, 2012

this assignment was one of my favorites, the idea was to build something with time. The assignment was named “Time Machine” We decide to create a coaster that reminds you when to drink water. We were aiming to the people that is sitting for long periodes of time in front of the computer and maybe forgets to drink water.

We calculate what we need to drink a zip every 5 minutes for 8 hours. So with the help of a light sensor when the bottle is put on the coaster a internal timer starts to run and when 5 minutes have past 6 lamps start to blink and a bip sound.

Picture:

Source CODE LRDsensor:




/*
 * Pablo Suzarte
 * Assignment 3 Hydro Coaster
 * Physical prototyping
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */

int LDR = A2; // select the input pin for the LDR
int ledPin = 13;
int ledPin2 = 12;
int ledPin3= 11;
int ledPin4 = 10;
int ledPin5= 9;
int ledPin6 = 8;
int desireTime = 3;
int ldrStateCompare = 700;

// select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
int ldrState= 0;
int outputPin = 7;

unsigned long start, finished, elapsed; //variable for the timer
int counter, total;

void setup() {
  
  pinMode(outputPin, OUTPUT);  
  pinMode(LDR, INPUT); // declare the LDR as an INPUT
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  
// declare the ledPin as an OUTPUT

  Serial.begin(9600);

}

void loop() {
  
  
    ldrState = analogRead(LDR);
    val = analogRead(LDR); // read the value from the sensor
    
    if(ldrState > ldrStateCompare){
      timer();
        
}
    else{
        
        counter= 0;
        }
 
}

void timer(){

  start=millis();
  delay(1000);
  total=counter++;

  if(total>=desireTime){
    
    for(int i=0;i<10;i++){
      playSound();
          digitalWrite(ledPin, HIGH);
          digitalWrite(ledPin2, HIGH);
          digitalWrite(ledPin3, HIGH);
          digitalWrite(ledPin4, HIGH);
          digitalWrite(ledPin5, HIGH);
          digitalWrite(ledPin6, HIGH);
         delay(1);
          digitalWrite(ledPin, LOW);
          digitalWrite(ledPin2, LOW);
          digitalWrite(ledPin3, LOW);
          digitalWrite(ledPin4, LOW);
          digitalWrite(ledPin5, LOW);
          digitalWrite(ledPin6, LOW);
    }

    }

}
void playSound(){
    digitalWrite(outputPin, HIGH);
    delayMicroseconds(1500);
    digitalWrite(outputPin, LOW);
    delayMicroseconds(1500);

}

Instructions:

PDF

Video!

Physical Prototyping: assignment 2 “Chess with a Twist”

Friday, March 30th, 2012

On this assignment we had to improve the game play of some classical table game. We choose Chess, the way that we “improve it” was by add some rules with lights (leds) and one button.
The idea was to make the game of chess a bit faster and stressy. Ones the player made a move it has to press the button and it will start the lights to randomly go on and off. The player has just 5 seconds to choose when to release the button. If is fast enough the lamp will stay under a piece of the opponent. This means the that piece has to leave the game. If the player don’t think fast can happen that the light will stay on one of his pieces. Pretty tricky game but really fun to develop.

We builded the whole game, just the pieces came from an existing old chess game.

Picture:

Source CODE CodeChessWithATwist:





/*
 * Pablo Suzarte
 * Assignment 2 chess with a twist
 * Physical prototyping
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */
int outputPin = 18; //Sound

int buttonPin = 19; 
int buttonState =0;

const int pinArray[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
int count = 0;
int randNumber;

int previous = LOW; 
int state = HIGH;
long time=100;
long debounce = 500;

  
void setup() {
   pinMode(outputPin, OUTPUT);  
  
  for ( count=0;count<16;count++){
    
    pinMode(pinArray[count], OUTPUT);
  }
  
  pinMode(buttonPin, INPUT);
  
  
}
 
void loop(){
  
  buttonState = digitalRead(buttonPin);
  
  if (buttonState  == LOW && millis() - time > debounce) {
    
    if (state == HIGH){
      
      state = LOW;
    }
    
    else{
      
      state = HIGH;
       randNumber = random(0, 16);
    }
    
     time = millis();    

for(int i=0; i<16; i++){
      digitalWrite(pinArray[i], LOW);
       playSound();
   } 
  }

 else  { 
        
    digitalWrite(pinArray[randNumber], HIGH);
    
    
 
  }
}
void playSound(){
    digitalWrite(outputPin, HIGH);
    delayMicroseconds(2500);
    digitalWrite(outputPin, LOW);
    delayMicroseconds(2500);

}

Instructions:
PDF

Here a video with some gameplay!

Physical Prototyping: assignment 1 “The bobbie”

Friday, March 30th, 2012

On this assignment we have to do a toy for adults using the Arduino The idea was to with help of a potentiometer turn on the leds on the bobbie.

Source CODE bobbie:




/*
 * Pablo Suzarte
 * Assignment 1
 * The Bobbie
 * Physical prototyping
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */

int sensorPin = A0;    // select the input pin for the potentiometer
     
int fadeValue = 0;    

void setup() {
  
  // declare the ledPin as an OUTPUT:
  
   pinMode(3, OUTPUT); 
   pinMode(5, OUTPUT);   
   pinMode(6, OUTPUT); 
   pinMode(9, OUTPUT); 
   pinMode(10, OUTPUT);   
   pinMode(11, OUTPUT);  
     
}

void loop() {
  

  
    for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) { 
        fadeValue = analogRead(sensorPin);    
            analogWrite(3, fadeValue/4);  
            analogWrite(5, fadeValue/4);
            analogWrite(6, fadeValue/4);
            analogWrite(9, fadeValue/4);  
            analogWrite(10, fadeValue/4);  
            analogWrite(11, fadeValue/4);  
  
            delay(fadeValue); 
            }   
   
    for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {  
        fadeValue = analogRead(sensorPin);    
            analogWrite(3, fadeValue/4); 
            analogWrite(5, fadeValue/4); 
            analogWrite(6, fadeValue/4);
            analogWrite(9, fadeValue/4); 
            analogWrite(10, fadeValue/4); 
            analogWrite(11, fadeValue/4);  
  
            delay(fadeValue);  
            }  
        }

Instructions & DIY Manual (2 PDfS)

DIY

How to use it

here an explanation of the process:

Java: Final Project “Busstavlan”

Friday, March 30th, 2012

Screenshot:

This is the final project of the java course.

Out concept was to simulate the screens that there is in the busstops in Skåne. So the idea was to do a widget för the desktop that gives you a simple interface with a search function. Ones the user add the departure and arrive destination, the widget will give you how many minutes there is left for the bus to arrive. If you press the info button you will get the info of how many times you have to change buses and it will give you all the details of your trip.

Because the program has so many clases I will add the zip file instead of the source codes.

This was a great experience for me personally. We worked with a system named SCRUM that helps you to divide the work depending what are you good at and at the same time gives you an estimation of how long time every taks will take. I was the SCRUM Master and Head programer.

Here u can download the zip file with all the classes:

Download busstavlan

Java: assignment 6 “Getting info from an XML”

Friday, March 30th, 2012

On this assignment we had to read a XML file from Skåne Trafikens API, this is the company that runs all the buses on the region of Skåne in
the south of Sweden.

The idea was to find the stations by searching names on a textfield.

Screenshot:

Source CODE Main:




/*
 * Pablo Suzarte
 * Assignment 6
 * XML READER
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.DefaultListModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

public class Main extends JFrame {

	/**
	 * Declare Variables
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private SkanetrafikenHandler dh = new SkanetrafikenHandler(this);
	private ArrayList<Point> points = new ArrayList<Point>();
	private JTextField textField_Search;
	private JList list;
	private JScrollPane scrollPane;
	private JButton button;
	private DefaultListModel mymodel = new DefaultListModel();
	private JOptionPane frame;
	public String station;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Main frame = new Main();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Main() {
		setForeground(Color.RED);
		setIconImage(Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/img/1330028595_61.png")));
		setTitle("Skanetrafiken by Pablo Suzarte");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 424);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		scrollPane = new JScrollPane();
		button = new JButton("Search");
		
		button.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				
				
					findStations(textField_Search.getText());

			}
		});

		textField_Search = new JTextField();
		textField_Search.setColumns(10);
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane
				.setHorizontalGroup(gl_contentPane
						.createParallelGroup(Alignment.TRAILING)
						.addGroup(
								gl_contentPane
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												gl_contentPane
														.createParallelGroup(
																Alignment.TRAILING)
														.addComponent(
																scrollPane,
																Alignment.LEADING,
																GroupLayout.DEFAULT_SIZE,
																428,
																Short.MAX_VALUE)
														.addComponent(
																button,
																GroupLayout.PREFERRED_SIZE,
																149,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																textField_Search,
																Alignment.LEADING,
																GroupLayout.DEFAULT_SIZE,
																428,
																Short.MAX_VALUE))
										.addContainerGap()));
		gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_contentPane
						.createSequentialGroup()
						.addContainerGap()
						.addComponent(textField_Search,
								GroupLayout.PREFERRED_SIZE,
								GroupLayout.DEFAULT_SIZE,
								GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(button)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE,
								301, GroupLayout.PREFERRED_SIZE)
						.addContainerGap(425, Short.MAX_VALUE)));

		list = new JList();
		list.addListSelectionListener(new ListSelectionListener() {

			public void valueChanged(ListSelectionEvent e) {

				station = (String) mymodel.get(list.getSelectedIndex());
				JOptionPane.showMessageDialog(frame,
						"The selected station is called: " + station
								+ " at the cordinates " + stadxy(station));

			}
		});

		list.setModel(mymodel);
		scrollPane.setViewportView(list);
		contentPane.setLayout(gl_contentPane);
	}
		
		public void findStations(String name){
			SAXParserFactory factory = SAXParserFactory.newInstance();

			try {
				
				SAXParser parser = factory.newSAXParser();
				parser.parse("http://www.labs.skanetrafiken.se/v2.2/querystation.asp?inpPointfr=" + name ,dh);
				
			} catch (Exception e) {
			
				e.printStackTrace();
			}
			
			for (int i = 0; i < points.size(); i++){
				mymodel.addElement(points.get(i).name);
		
			}
			
		
		
		
	}

	/**
	 * @return the points
	 */
	public ArrayList<Point> getPoints() {
		return points;
	}

	/**
	 * @param points
	 *            the points to set
	 */
	public void setPoints(ArrayList<Point> points) {
		this.points = points;
	}



	private String stadxy(String name) {
		for (int i = 0; i < mymodel.size(); i++) {
			if (mymodel.get(i).equals(name)) {
				return "X: " + points.get(i).x + " Y: " + points.get(i).y;
			}
		}
		return null;
	}
}

Source CODE Point:




public class Point implements Comparable<Point> {

	public String name;
	public String x;
	public String y;

	@Override
	public int compareTo(Point o) {
		// return o.name.compareTo(this.name);
		return this.name.compareTo(o.name);
	}
}

Source CODE SkanetrafikenHandler:




import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class SkanetrafikenHandler extends DefaultHandler {

	@SuppressWarnings("unused")
	private boolean Point;
	private boolean Name;
	private boolean X;
	private boolean Y;
	private Point p;
	private Main mymodel;

	public SkanetrafikenHandler(Main parent) {
		mymodel = parent;
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		if (qName.equals("Point")) {
			Point = true;
			p = new Point();
		}
		if (qName.equals("Name")) {
			Name = true;
		}
		if (qName.equals("X")) {
			X = true;
		}
		if (qName.equals("Y")) {
			Y = true;
		}
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		if (qName.equals("Point")) {
			Point = false;
			mymodel.getPoints().add(p);
		}
		if (qName.equals("Name")) {
			Name = false;
		}
		if (qName.equals("X")) {
			X = false;
		}
		if (qName.equals("Y")) {
			Y = false;
		}
	}

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		if (Name == true) {
			p.name = new String(ch, start, length);
		}
		if (X == true) {
			p.x = new String(ch, start, length);
		}
		if (Y == true) {
			p.y = new String(ch, start, length);
		}
	}

}

Java: assignment 5 “Digital Clock”

Friday, March 30th, 2012

On this assignment we had to create a digital clock with help of a swingworker

Screenshot:

Source CODE DigitalClockGUI:




/*
 * Pablo Suzarte
 * Assignment 1
 * Windows Builder
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextArea;

public class DigitalClockGUI extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JLabel clockLabel;
	
	private String time;
	private String _hours;
    private String _minutes;
    private String _seconds;
	
    private String myHour;
    private String myMin;
    private String mySec;
    
    int alarmHour;
    int alarmMinute;
    int alarmSecond ;
    
	private ClockLogic myClock;
	private JTextArea textArea_hrs;
	private JTextArea textArea_min;
	private JTextArea textArea_sec;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					DigitalClockGUI frame = new DigitalClockGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public DigitalClockGUI() {
		myClock = new ClockLogic(DigitalClockGUI.this);
        myClock.execute();//execute the Clock 
		
		setTitle("Digital Clock");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 339, 324);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton btnAlarm = new JButton("Set the Alarm");
		btnAlarm.setFont(new Font("Arial", Font.BOLD, 14));
		btnAlarm.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				/**
				 * Gets 3 different values from the textAreas
				 */
				 
				myHour = new String (textArea_hrs.getText());
				myMin = new String (textArea_min.getText());
				mySec = new String (textArea_sec.getText());
				
				/**
				 * Transform the 3 values from the textAreas to Integer
				 */
				 
				
			    int _alarmHour = Integer.parseInt(myHour);
			    int _alarmMinute = Integer.parseInt(myMin);
			    int _alarmSecond = Integer.parseInt(mySec);
				
			    /**
				 * Set the alarm from the textArea values
				 */

			    alarmHour = _alarmHour;
			    alarmMinute = _alarmMinute;
			    alarmSecond = _alarmSecond;
			    
			    myClock.setBoolean(true);
			    
			    
			    myClock.setAlarm(alarmHour, alarmMinute, alarmSecond); // set the alarm
			    
			    System.out.println("Alarm set at: " + alarmHour +":"+ alarmMinute + ":" + alarmSecond); // shows on the console what time the alarm has been set up
			    
			    
			   
			}
		});
		btnAlarm.setBounds(216, 172, 117, 124);
		contentPane.add(btnAlarm);
		
		clockLabel = new JLabel("");
		clockLabel.setHorizontalAlignment(SwingConstants.CENTER);
		clockLabel.setFont(new Font("Arial", Font.BOLD, 50));
		clockLabel.setBounds(30, 25, 277, 92);
		contentPane.add(clockLabel);
		
		textArea_sec = new JTextArea();
		textArea_sec.setFont(new Font("Arial", Font.BOLD, 50));
		textArea_sec.setBounds(146, 207, 58, 65);
		contentPane.add(textArea_sec);
		
		textArea_min = new JTextArea();
		textArea_min.setFont(new Font("Arial", Font.BOLD, 50));
		textArea_min.setBounds(76, 207, 58, 65);
		contentPane.add(textArea_min);
		
		textArea_hrs = new JTextArea();
		textArea_hrs.setFont(new Font("Arial", Font.BOLD, 50));
		textArea_hrs.setBounds(6, 207, 58, 65);
		contentPane.add(textArea_hrs);
		
		JLabel lblHrs = new JLabel("Hrs.");
		lblHrs.setBounds(6, 188, 61, 16);
		contentPane.add(lblHrs);
		
		JLabel lblMin = new JLabel("Min");
		lblMin.setBounds(73, 188, 61, 16);
		contentPane.add(lblMin);
		
		JLabel lblSec = new JLabel("Sec");
		lblSec.setBounds(143, 188, 61, 16);
		contentPane.add(lblSec);
	}
	
	public void setTime(int hour, int minutes, int seconds){
		
		/**
		 * this method makes the clock work on the ClockLabel
		 */
		
        _hours=Integer.toString(hour);
        _minutes=Integer.toString(minutes);
        _seconds=Integer.toString(seconds);
        
        /**
		 * the if help to put a 0 if it is necessary
		 */
        
        if(hour < 10){
	    	   
	    	   _hours = "0" + _hours;
	       }
	       
	       if(minutes < 10)
	       {
	    	   _minutes = "0" + _minutes;
	       }
	       if(seconds < 10)
	       {
	    	   _seconds = "0" + _seconds;
	       }
        
        time = _hours + ":" +   _minutes + ":" + _seconds;
        
        clockLabel.setText(time); //Paint the clock on the ClockLabel
		
	}
	
	public void invokeAlarm(){
		/**
		 * Changes the color of the background when the alarm starts
		 */
		Color d = new Color((float) Math.random(), (float) Math.random(),(float) Math.random());
        contentPane.setBackground(d);
        textArea_hrs.setText("");
	    textArea_min.setText("");
	    textArea_sec.setText("");
        
		
	}
}

Source CODE Clock Logic:




import java.util.Calendar;
import java.util.List;

import javax.swing.SwingWorker;

public class ClockLogic extends SwingWorker<Void, Void>{
	
	DigitalClockGUI clock;
	private int time_hours;
	private int time_minutes;
	private int time_seconds;
	private int alarm_hours;
	private int alarm_minutes;
	private int alarm_seconds;
	private boolean alarm;
	
	public ClockLogic(DigitalClockGUI gui){
		
		clock = gui;
	}
	
	@Override
	protected Void doInBackground() throws Exception {
		
		while(isCancelled() == false)
		{
			/**
			 * This If check if the numbers form the textAreas match the current time so activates the Alarm
			 */
			if(time_hours == alarm_hours && time_minutes == alarm_minutes && time_seconds == alarm_seconds && alarm == true){
				
				clock.invokeAlarm();
				System.out.println("WAKE UP!");
				
			}
		this.publish();
		Thread.sleep(1000);
		}

		return null;
	}
	
	
	protected void process(List<Void> chunks) {
		
		/**
		 * Gets the time from the computer that the program is running
		 */
	    
		Calendar myTime = Calendar.getInstance();
        time_hours = myTime.get(Calendar.HOUR_OF_DAY);
        time_minutes = myTime.get(Calendar.MINUTE);
        time_seconds = myTime.get(Calendar.SECOND);
         
        clock.setTime(time_hours, time_minutes, time_seconds);
        

	}
	
	
	public void setAlarm(int hours, int minutes, int second){
		alarm_hours = hours;
		alarm_minutes = minutes;
		alarm_seconds = second;
	}
	
	public void setBoolean(boolean Alarm){
		alarm = Alarm;
	}
	

}

Java: assignment 4 “Object Relationships”

Friday, March 30th, 2012

One-way association:

On this assignment we had to create a class Dog and a class of Human. The human can have one or no dog, and that a dog has one or no owner. The dog does not know if it has an owner.

Screenshot:

Source CODE:




/*
 * Pablo Suzarte
 * Assignment 1
 * Windows Builder
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */
package se.mah.pablo;

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;

public class GUI extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	String nh1, bd1;
	boolean buttonPress;
	private JTextArea textArea_nh;
	private JTextArea textArea_bd;
	private JButton newHuman;
	private JButton buyDog;
	private JButton printInfo;
	private JTextArea textArea_info;
	private JTextArea textArea_em;

	private Human myHuman;
	private Dog myDog;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					GUI frame = new GUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public GUI() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 427, 340);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		textArea_nh = new JTextArea();
		textArea_nh.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
		
		textArea_bd = new JTextArea();
		textArea_bd.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
		
		textArea_info = new JTextArea();
		textArea_info.setFont(new Font("Lucida Grande", Font.PLAIN, 11));
		textArea_info.setEditable(false);
		
		textArea_em = new JTextArea();
		textArea_em.setFont(new Font("Lucida Grande", Font.PLAIN, 11));
		textArea_em.setEditable(false);
		
		newHuman = new JButton("New Human");
		newHuman.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
			
				myHuman = new Human (textArea_nh.getText()); 
				myHuman.getName();// Get text from the text area
				
			}
		});
		
		buyDog = new JButton("Buy Dog");
		buyDog.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(textArea_bd.getText().length()>0){//check if the buy dog textArea is empty
			myDog = new Dog (textArea_bd.getText());
			myHuman.buyDog(myDog);
			}
			
			}
		});
		
		printInfo = new JButton("GET Info");
		printInfo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textArea_info.setText(myHuman.getInfo());

				buttonPress = true;
					
				if(buttonPress==true){
					
					textArea_info.setText(myHuman.getInfo());//put the name of the Human and dog on the info text area
					textArea_em.setText(" ");
					
				}
	
				if(myHuman.getName() == null || myHuman.getName().length()<=2){ //if the text areas are empty or has less then 3 char give u an error msg
						
					textArea_info.setText(" ");
					textArea_em.setText("One of the fields or needs more then 2 Characters");
					
				
				}
				
			}
		});
		
		JLabel info = new JLabel("Info");
		info.setFont(new Font("Lucida Grande", Font.PLAIN, 20));
		
		JLabel lblErrorMessage = new JLabel("Error Message");
		lblErrorMessage.setFont(new Font("Lucida Grande", Font.PLAIN, 20));
		
		
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
								.addComponent(textArea_info, GroupLayout.PREFERRED_SIZE, 397, GroupLayout.PREFERRED_SIZE)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
										.addComponent(info)
										.addComponent(textArea_nh, GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
										.addComponent(textArea_bd, GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE))
									.addPreferredGap(ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
									.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
										.addComponent(printInfo, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
										.addComponent(newHuman, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
										.addComponent(buyDog, GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE))))
							.addGap(37))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(lblErrorMessage)
							.addContainerGap(299, Short.MAX_VALUE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(textArea_em, GroupLayout.PREFERRED_SIZE, 395, GroupLayout.PREFERRED_SIZE)
							.addContainerGap(39, Short.MAX_VALUE))))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(newHuman, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
						.addComponent(textArea_nh, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(textArea_bd, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
						.addComponent(buyDog))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addComponent(info, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
						.addComponent(printInfo, GroupLayout.PREFERRED_SIZE, 47, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(textArea_info, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE)
					.addGap(18)
					.addComponent(lblErrorMessage)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(textArea_em, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(62, Short.MAX_VALUE))
		);
		contentPane.setLayout(gl_contentPane);
	}
	

}


<strong>Source CODE Human:</strong>
1


package se.mah.pablo;

public class Human {
	
	private Dog _dog;
	private String _name;
	
	public Human(String name){
		
		_name = name;
		
	}
	
	public String getName(){
		
		return _name;
	}

	public void buyDog(Dog dog){
	
		this._dog = dog;
	
	
	}

	public String  getInfo(){
		if(_dog!=null){
		return _name + "is the owner of the dog named " + _dog.getName();//this if helps u to check if the dog area is empty or not then add the text to the getInfo()
		}else return _name + " does not own a dog";
		}
	
	

}

Source CODE Dog:




package se.mah.pablo;

public class Dog {
	
	private String _name;
	
	public Dog(String name){
		
		 _name = name;
	}
	
	public String getName(){
		if(_name==null){
			
			return "NO DOG HERE!";
		}
		
		return _name;
	}

	

}

Java: assignment 3 “Calculator”

Friday, March 30th, 2012

On this assignment we had to do a calculator:

Screenshot:

Source CODE CalculatorGUI:





/*
 * Pablo Suzarte
 * Assignment 1
 * Windows Builder
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */

package pablos.lab;

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;
import javax.swing.ImageIcon;
import java.awt.Toolkit;

public class CalculatorGUI extends JFrame {

	/**
	 * 
	 */
	
	//Declare all the Variables
	
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JButton button7;
	private JButton button8;
	private JButton button9;
	private JButton buttonAddition;
	private JButton button4;
	private JButton button5;
	private JButton button6;
	private JButton buttonSubtraction;
	private JButton button1;
	private JButton button2;
	private JButton button3;
	private JButton buttonMultiply;
	private JButton buttonClear;
	private JButton button0;
	private JButton buttonEquals;
	private JButton buttonDivide;
	private JTextArea textArea;
	Calculator nummerRakning;

	
	boolean flag = true; 
	
	int divC = 0;
	int addC = 0;
	int subtC = 0;
	int multiC = 0;
	
	double num1=0;
	double num2=0;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CalculatorGUI frame = new CalculatorGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CalculatorGUI() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(CalculatorGUI.class.getResource("/images/1328184507_Calculator.png")));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 270, 400);
			
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnFile = new JMenu("File");
		menuBar.add(mnFile);
		
		JMenuItem mntmClose = new JMenuItem("Close");
		mntmClose.setIcon(new ImageIcon(CalculatorGUI.class.getResource("/images/1326824461_button_cancel.png")));
		mntmClose.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		mnFile.add(mntmClose);
		
		JMenu mnHelp = new JMenu("Help");
		menuBar.add(mnHelp);
		
		JMenuItem mntmAbout = new JMenuItem("About");
		mntmAbout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				About about = new About();
				about.setVisible(true);
			}
		});
		mntmAbout.setIcon(new ImageIcon(CalculatorGUI.class.getResource("/images/1326838484_Information.png")));
		mnHelp.add(mntmAbout);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		//TEXT OF THE CALCULATOR
		
		textArea = new JTextArea();
		textArea.setFont(new Font("Tahoma", Font.BOLD, 25));
		textArea.setBounds(20, 11, 226, 56);
		contentPane.add(textArea);
		
		//BUTTONS: NUMBERS
		
		button1 = new JButton("1");
		button1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == button1) {
					
					textArea.append("1");
					if(flag == true){
						
						num1=num1*10+1;
						
				
					}else{
						
						num2=num2*10+1;
						
					}
				}
			}
		});
		button1.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button1.setBounds(20, 196, 50, 50);
		contentPane.add(button1);
		
		button2 = new JButton("2");
		button2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == button2) {
					
					textArea.append("2");
					if(flag == true){
						
						num1=num1*10+2;
				
					}else{
						
						num2=num2*10+2;
						//flag = true;
					}
				}
			}
		});
		button2.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button2.setBounds(80, 196, 50, 50);
		contentPane.add(button2);
		
		button3 = new JButton("3");
		button3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == button3) {
					
					textArea.append("3");
					if(flag == true){
						
						num1=num1*10+3;
				
					}else{
						
						num2=num2*10+3;
						//flag = true;
					}
				}
			}
		});
		button3.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button3.setBounds(140, 196, 50, 50);
		contentPane.add(button3);
		
		
		button4 = new JButton("4");
		button4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == button4) {
					
					textArea.append("4");
					if(flag == true){
						
						num1=num1*10+4;
				
					}else{
						
						num2=num2*10+4;
						//flag = true;
					}
				}
			}
		});
		button4.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button4.setBounds(20, 135, 50, 50);
		contentPane.add(button4);
		
		button5 = new JButton("5");
		button5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == button5) {
					
					textArea.append("5");
					if(flag == true){
						;
						num1=num1*10+5;
				
					}else{
						
						num2=num2*10+5;
						//flag = true;
					}
				}
			}
		});
		button5.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button5.setBounds(80, 139, 50, 50);
		contentPane.add(button5);
		
		button6 = new JButton("6");
		button6.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == button6) {
					
					textArea.append("6");
					if(flag == true){
						
						num1=num1*10+6;
				
					}else{
						
						num2=num2*10+6;
						//flag = true;
					}
				}
			}
		});
		button6.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button6.setBounds(140, 139, 50, 50);
		contentPane.add(button6);
		
		
		
		button7 = new JButton("7");
		button7.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == button7) {
					
					textArea.append("7");
					if(flag == true){
					
						num1=num1*10+7;
				
					}else{
						
						num2=num2*10+7;
						//flag = true;
					}
				}
			}
		});
		button7.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button7.setBounds(20, 78, 50, 50);
		contentPane.add(button7);
		
		button8 = new JButton("8");
		button8.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == button8) {
					
					textArea.append("8");
					if(flag == true){
					
						num1=num1*10+8;
				
					}else{
				
						num2=num2*10+8;
						//flag = true;
					}
				}
			}
		});
		button8.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button8.setBounds(80, 78, 50, 50);
		contentPane.add(button8);
		
		button9 = new JButton("9");
		button9.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == button9) {
					
					textArea.append("9");
					if(flag == true){
						
						num1=num1*10+9;
				
					}else{
						
						num2=num2*10+9;
						//flag = true;
					}
				}
			}
		});
		button9.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button9.setBounds(140, 78, 50, 50);
		contentPane.add(button9);
		
		
		
		button0 = new JButton("0");
		button0.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == button0) {
					
					textArea.append("0");
					if(flag == true){
						
						num1=num1*10+0;
				
					
					}else{
						
						num2=num2*10+0;
						//flag = true;
					}
				}
			}
		});
		button0.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button0.setBounds(80, 257, 50, 50);
		contentPane.add(button0);
		
		//BUTTONS: OPERATIONS
		
		//BUTTON +
		buttonAddition = new JButton("+");
		buttonAddition.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == buttonAddition) {
					flag = false;
					textArea.append("+");
					divC = 0;
					addC = 1;
					subtC = 0;
					multiC = 0;		
			}
			}
		
		});
		buttonAddition.setFont(new Font("Tahoma", Font.PLAIN, 16));
		buttonAddition.setBounds(200, 78, 50, 50);
		contentPane.add(buttonAddition);
		
		//BUTTON *		
		buttonMultiply = new JButton("*");
		buttonMultiply.setFont(new Font("Tahoma", Font.PLAIN, 16));
		buttonMultiply.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == buttonMultiply) {
					flag = false;
					textArea.append("*");
					divC = 0;
					addC = 0;
					subtC = 0;
					multiC = 1;
					
					
					
			}
			}
		
		});
		buttonMultiply.setBounds(200, 196, 50, 50);
		contentPane.add(buttonMultiply);
		//BUTTON -		
		buttonSubtraction = new JButton("-");
		buttonSubtraction.setFont(new Font("Tahoma", Font.PLAIN, 16));
		buttonSubtraction.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == buttonSubtraction) {
					flag = false;
					textArea.append("-");
					divC = 0;
					addC = 0;
					subtC = 1;
					multiC = 0;
				
			}
			}
		}
		);
		buttonSubtraction.setBounds(200, 139, 50, 50);
		contentPane.add(buttonSubtraction);
		//BUTTON /		
		buttonDivide = new JButton("/");
		buttonDivide.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == buttonDivide) {
					flag = false;
					textArea.append("/");
					divC = 1;
					addC = 0;
					subtC = 0;
					multiC = 0;
					
				}
				
			}
		});
		buttonDivide.setFont(new Font("Tahoma", Font.PLAIN, 16));
		buttonDivide.setBounds(200, 257, 50, 50);
		contentPane.add(buttonDivide);
		
		buttonClear = new JButton("C");
		buttonClear.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if(source == buttonClear){
				
					textArea.setText("");
					num1=0;
					num2=0;
					flag = true;
				}
				
			
			}
		});
		buttonClear.setFont(new Font("Tahoma", Font.PLAIN, 16));
		buttonClear.setBounds(20, 257, 50, 50);
		contentPane.add(buttonClear);
		
		
		
		buttonEquals = new JButton("=");
		buttonEquals.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object source = e.getSource();
				if (source == buttonEquals) {
					
					if(divC==1){
						
						
						double result = Calculator.divideValues(num1,num2);
						
						textArea.setText(Double.toString(result));
						
						num1=result;
						flag=true;
						
						
					
					}
					if(addC==1){
						
						
						
						
						double result = Calculator.addValues(num1,num2);
					
						textArea.setText(Double.toString(result));
						num1=result;
						flag=true;
						
				
					}
					if(multiC==1){
	
						
	
						double result = Calculator.multiplyValues(num1,num2);
						
						textArea.setText(Double.toString(result));
						
						num1=result;
						flag=true;

					}
					if(subtC==1){
	
						
						double result = Calculator.subtractValues(num1,num2);
						
						textArea.setText(Double.toString(result));
						
						num1=result;
						flag=true;
					}
				}
				
			}
		});
		buttonEquals.setFont(new Font("Tahoma", Font.PLAIN, 16));
		buttonEquals.setBounds(140, 257, 50, 50);
		contentPane.add(buttonEquals);
		
		
	}
	
	

}

Source CODE Calculator (Logic):




	package pablos.lab;

public class Calculator {

	
	public static double divideValues(double x, double y) { //This methods divide values
		
		double result = x/y;
		return result;
}

	public static double multiplyValues(double x, double y) { //This methods multiply values
	
	
		
		double result = x*y;
		return result;
}

	public static double subtractValues(double x, double y) { //This methods subtract values
	
	
		double result = x-y;
		return result;
}

	public static double addValues(double x, double y) //This methods add values

 {
		double result = x+y;
		return result;
}
	
	
}

Source CODE About:




package pablos.lab;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;

public class About extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			About dialog = new About();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public About() {
		setTitle("About");
		setIconImage(Toolkit.getDefaultToolkit().getImage(About.class.getResource("/images/friskis_o_svettis_78548586_116130886.gif")));
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.EAST);
		
		JLabel lblDevelopByPablo = new JLabel("Develop by Pablo Suzarte \u00A9 2012");
		lblDevelopByPablo.setFont(new Font("Tahoma", Font.PLAIN, 16));
		
		JLabel lblpablosu = new JLabel("@pablosu");
		lblpablosu.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblpablosu.setIcon(new ImageIcon(About.class.getResource("/images/48x48_icontexto-inside-twitter.png")));
		
		JLabel label = new JLabel("@pablosu");
		label.setIcon(new ImageIcon(About.class.getResource("/images/1326989302_icontexto-inside-facebook.png")));
		label.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JLabel label_1 = new JLabel("@pablosu");
		label_1.setIcon(new ImageIcon(About.class.getResource("/images/1326991198_icontexto-inside-linkedin.png")));
		label_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon(About.class.getResource("/images/1326990419_human-folder-development.png")));
		
		JLabel label_2 = new JLabel("@pablosu");
		label_2.setIcon(new ImageIcon(About.class.getResource("/images/1326989330_icontexto-inside-google.png")));
		label_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JLabel lblFiskisSvetis = new JLabel("Calculator 0.1");
		lblFiskisSvetis.setFont(new Font("Tahoma", Font.PLAIN, 23));
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.TRAILING)
				.addGroup(Alignment.LEADING, gl_contentPanel.createSequentialGroup()
					.addGap(41)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.TRAILING)
						.addComponent(lblDevelopByPablo)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPanel.createSequentialGroup()
									.addComponent(lblpablosu)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(label, GroupLayout.PREFERRED_SIZE, 112, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_contentPanel.createSequentialGroup()
									.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 112, GroupLayout.PREFERRED_SIZE)
									.addGap(18)
									.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 112, GroupLayout.PREFERRED_SIZE)))
							.addGap(18)
							.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 119, GroupLayout.PREFERRED_SIZE))
						.addGroup(Alignment.LEADING, gl_contentPanel.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(lblFiskisSvetis, GroupLayout.PREFERRED_SIZE, 375, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(28, Short.MAX_VALUE))
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblFiskisSvetis, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
					.addGap(25)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(label, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblpablosu))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
								.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)))
						.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 102, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
					.addComponent(lblDevelopByPablo))
		);
		contentPanel.setLayout(gl_contentPanel);
	}
}

Java: assignment 2 “Jtables and New Members”

Friday, March 30th, 2012

On this assignment we have to add the function to add members to a JTable

The code is divided in 4 clases.

Screenshot:

Source CODE Main:




/*
 * Pablo Suzarte
 * Assignment 2
 * JTable
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */

import java.awt.Color;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;


@SuppressWarnings("serial")
public class Main extends JFrame {

	private JPanel contentPane;
	private JTable table;
	private DefaultTableModel model;
	private JMenuBar menuBar;
	private JMenu mnNewMenu;
	private JMenuItem mntmNew;
	private JMenuItem mntmOpen;
	private JMenuItem mntmClose;
	private JMenu mnNewMenu_1;
	private JMenuItem mntmNewMember;
	private JMenuItem mntmFindMember;
	private JTextField textField;
	private JButton Search;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Main frame = new Main();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	// this add a new member on the top table
	
	public void addNewMember(String name, String idnumber, String address, String phone, String email) {
		model.insertRow(0, new Object[] {
		 name,
		 idnumber,
		 address,
		 phone,
		 email
		});
	}
	


	/**
	 * Create the frame.
	 */
	public Main() {
		setTitle("Friskis och Svettis");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 800, 600);
		
		menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		mnNewMenu = new JMenu("File");
		mnNewMenu.setFont(new Font("Segoe UI", Font.PLAIN, 16));
		menuBar.add(mnNewMenu);
		
		mntmNew = new JMenuItem("New");
		mntmNew.setIcon(new ImageIcon(Main.class.getResource("/images/1326824571_filenew.png")));
		mntmNew.setFont(new Font("Segoe UI", Font.PLAIN, 16));
		mnNewMenu.add(mntmNew);
		
		mntmOpen = new JMenuItem("Open");
		mntmOpen.setIcon(new ImageIcon(Main.class.getResource("/images/1326824544_folder_horizontal_open.png")));
		mntmOpen.setFont(new Font("Segoe UI", Font.PLAIN, 16));
		mnNewMenu.add(mntmOpen);
		
		mntmClose = new JMenuItem("Close");
		mntmClose.setIcon(new ImageIcon(Main.class.getResource("/images/1326824461_button_cancel.png")));
		mntmClose.addActionListener(new ActionListener() {
			
				//Exit the Application via pressing the exit button on the drop menu
			
				public void actionPerformed(ActionEvent arg0) {
			
					System.exit(0);
				}
			
		});
		mntmClose.setFont(new Font("Segoe UI", Font.PLAIN, 16));
		mnNewMenu.add(mntmClose);
		
		Component horizontalStrut = Box.createHorizontalStrut(12);
		menuBar.add(horizontalStrut);
		
		mnNewMenu_1 = new JMenu("Members");
		mnNewMenu_1.setFont(new Font("Segoe UI", Font.PLAIN, 16));
		menuBar.add(mnNewMenu_1);
		
		mntmNewMember = new JMenuItem("New Member");
		mntmNewMember.setIcon(new ImageIcon(Main.class.getResource("/images/1326824652_business-contact.png")));
		mntmNewMember.setFont(new Font("Segoe UI", Font.PLAIN, 16));
		mntmNewMember.addActionListener(new ActionListener() {
			
			//Open Add New Member button
			public void actionPerformed(ActionEvent e) {
				
				newMember addNewMember = new newMember(Main.this);
				addNewMember.setVisible(true);
				

			}
		});
		
		mnNewMenu_1.add(mntmNewMember);
		
		mntmFindMember = new JMenuItem("Find Member");
		mntmFindMember.setIcon(new ImageIcon(Main.class.getResource("/images/1326824635_search_16.png")));
		mntmFindMember.addActionListener(new ActionListener() {
			
			// open the search for a member from the drop menu "members"
						public void actionPerformed(ActionEvent e) {
							Find findContact = new Find();
							findContact.setVisible(true);
						}
		});
		mntmFindMember.setFont(new Font("Segoe UI", Font.PLAIN, 16));
		mnNewMenu_1.add(mntmFindMember);
		
		Component horizontalStrut_1 = Box.createHorizontalStrut(12);
		menuBar.add(horizontalStrut_1);
		
		JMenu mnHelp = new JMenu("Help");
		mnHelp.setFont(new Font("Segoe UI", Font.PLAIN, 16));
		menuBar.add(mnHelp);
		
		JMenuItem mntmAbout = new JMenuItem("About");
		mntmAbout.setIcon(new ImageIcon(Main.class.getResource("/images/1326838484_Information.png")));
		mntmAbout.addActionListener(new ActionListener() {
			//Open the about window
			public void actionPerformed(ActionEvent arg0) {
				About about = new About();
				about.setVisible(true);
			}
		});
		mntmAbout.setFont(new Font("Segoe UI", Font.PLAIN, 16));
		mnHelp.add(mntmAbout);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 122, 774, 334);
		
		table = new JTable();
				
		model = new DefaultTableModel(
			new Object[][] {},
			new String[] {
				"Name", "ID Number", "Address", "Phone",  "E-mail"
			}
		);
		table.setModel(model);
		scrollPane.setViewportView(table);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon(Main.class.getResource("/images/1326716854_physical_education.png")));
		
		JLabel lblFriskisOchSvettis = new JLabel("Friskis och Svettis");
		lblFriskisOchSvettis.setIcon(new ImageIcon(Main.class.getResource("/images/48x48-f-o-s.png")));
		lblFriskisOchSvettis.setForeground(Color.BLACK);
		lblFriskisOchSvettis.setFont(new Font("Tahoma", Font.PLAIN, 24));
		
		textField = new JTextField();
		textField.setColumns(10);
		
		Search = new JButton("");
		Search.setFont(new Font("Tahoma", Font.PLAIN, 16));
		Search.setIcon(new ImageIcon(Main.class.getResource("/images/1326824635_search_16.png")));
		Search.setSelectedIcon(new ImageIcon(Main.class.getResource("/images/1326824635_search_16.png")));
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addGap(3)
									.addComponent(textField, GroupLayout.PREFERRED_SIZE, 249, GroupLayout.PREFERRED_SIZE))
								.addComponent(lblFriskisOchSvettis, GroupLayout.PREFERRED_SIZE, 252, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(Search, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(label, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE))
						.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 753, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(11, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addComponent(label, GroupLayout.PREFERRED_SIZE, 107, GroupLayout.PREFERRED_SIZE)
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
								.addComponent(Search)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(lblFriskisOchSvettis, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
									.addGap(30)
									.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
							.addPreferredGap(ComponentPlacement.RELATED, 10, Short.MAX_VALUE)))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 403, GroupLayout.PREFERRED_SIZE))
		);
		contentPane.setLayout(gl_contentPane);
		
		

		

	}

}






Source CODE NewMember:




import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.SystemColor;
import javax.swing.UIManager;
import javax.swing.ImageIcon;
import java.awt.Toolkit;


public class newMember extends JDialog {


	private final JPanel contentPanel = new JPanel();
	private JTextField textName;
	private JTextField textIdnumber;
	private JTextField textAddress;
	private JTextField textPhone;
	private JTextField textEmail;

	//private main parent;
	
	//private main myMain = parent;


	public static void main(String[] args) {
		try {
			newMember dialog = new newMember(null);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}



	public newMember(JFrame parent) { // Still don't get this parameter hwo works
		setIconImage(Toolkit.getDefaultToolkit().getImage(newMember.class.getResource("/images/48x48-f-o-s.png")));
		
		final Main minParent = (Main) parent; //Still don't get what is this
		
		setBounds(100, 100, 558, 418);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBackground(SystemColor.window);
		panel.setBounds(0, 0, 542, 347);
		contentPanel.add(panel);
		
		textName = new JTextField();
		textName.setColumns(10);
		textName.setBounds(115, 38, 215, 20);
		panel.add(textName);
		
		textIdnumber = new JTextField();
		textIdnumber.setColumns(10);
		textIdnumber.setBounds(115, 69, 215, 20);
		panel.add(textIdnumber);
		
		textAddress = new JTextField();
		textAddress.setColumns(10);
		textAddress.setBounds(115, 100, 215, 20);
		panel.add(textAddress);
		
		textPhone = new JTextField();
		textPhone.setColumns(10);
		textPhone.setBounds(115, 131, 215, 20);
		panel.add(textPhone);
		
		textEmail = new JTextField();
		textEmail.setColumns(10);
		textEmail.setBounds(115, 162, 215, 20);
		panel.add(textEmail);
		
		JLabel lblName = new JLabel("Name : ");
		lblName.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblName.setBounds(48, 33, 57, 20);
		panel.add(lblName);
		
		JLabel lblIdNumber = new JLabel("ID Number : ");
		lblIdNumber.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblIdNumber.setBounds(10, 69, 95, 17);
		panel.add(lblIdNumber);
		
		JLabel lblAddress = new JLabel("Address : ");
		lblAddress.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblAddress.setBounds(32, 99, 73, 19);
		panel.add(lblAddress);
		
		JLabel lblPhone = new JLabel("Phone : ");
		lblPhone.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblPhone.setBounds(45, 131, 60, 17);
		panel.add(lblPhone);
		
		JLabel lblEmail = new JLabel("E-Mail : ");
		lblEmail.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblEmail.setBounds(45, 160, 60, 20);
		panel.add(lblEmail);
		
		JButton btnNewButton = new JButton("add photo");
		btnNewButton.setIcon(new ImageIcon(newMember.class.getResource("/images/1326991898_user_48.png")));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnNewButton.setBounds(355, 37, 154, 145);
		panel.add(btnNewButton);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("Save");
				okButton.setIcon(new ImageIcon(newMember.class.getResource("/images/1326826169_stock_save.png")));
				okButton.setFont(new Font("Tahoma", Font.PLAIN, 16));
				okButton.addActionListener(new ActionListener() {
					
					// when you press the Save button this action save the data on the correct cell on the jTable
					
					public void actionPerformed(ActionEvent e) {
						
						minParent.addNewMember(textName.getText(), textIdnumber.getText(), textAddress.getText(), textPhone.getText(), textEmail.getText());
						setVisible(false); 
					    dispose(); 
                }
				});
				
				okButton.setActionCommand("Save");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setIcon(new ImageIcon(newMember.class.getResource("/images/1326826193_Cancel.png")));
				cancelButton.setFont(new Font("Tahoma", Font.PLAIN, 16));
				cancelButton.addActionListener(new ActionListener() {
					
					// when you press the Cancel Button just the New Member window closes and not the whole program
					
					public void actionPerformed(ActionEvent e) {
						
						setVisible(false); 
						dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
}

Source CODE Find:







import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Toolkit;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ImageIcon;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class Find extends JFrame {

	private JPanel contentPane;
	private JTextField textField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Find frame = new Find();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Find() {
		setTitle("Find Member");
		setIconImage(Toolkit.getDefaultToolkit().getImage(Find.class.getResource("/images/48x48-f-o-s.png")));
		setBounds(100, 100, 513, 113);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		textField = new JTextField();
		textField.setColumns(10);
		
		JButton btnNewButton = new JButton("Search");
		btnNewButton.setIcon(new ImageIcon(Find.class.getResource("/images/1326971810_xmag.png")));
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(101)
					.addComponent(textField, GroupLayout.PREFERRED_SIZE, 210, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(btnNewButton)
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnNewButton))
					.addContainerGap(299, Short.MAX_VALUE))
		);
		contentPane.setLayout(gl_contentPane);
	}
}


Source CODE About:




/*
 * Pablo Suzarte
 * Assignment 2
 * JTable
 * Interaction Design
 * Malmö University
 * contact me: pablosu@gmail.com
 */

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;

@SuppressWarnings("serial")
public class About extends JDialog {

	private final JPanel contentPanel = new JPanel();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			About dialog = new About();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public About() {
		setTitle("About Develop by Pablo Suzarte");
		setIconImage(Toolkit.getDefaultToolkit().getImage(About.class.getResource("/images/friskis_o_svettis_78548586_116130886.gif")));
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.EAST);
		
		JLabel lblDevelopByPablo = new JLabel("Develop by Pablo Suzarte \u00A9 2011");
		lblDevelopByPablo.setFont(new Font("Tahoma", Font.PLAIN, 16));
		
		JLabel lblpablosu = new JLabel("@pablosu");
		lblpablosu.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblpablosu.setIcon(new ImageIcon(About.class.getResource("/images/48x48_icontexto-inside-twitter.png")));
		
		JLabel label = new JLabel("@pablosu");
		label.setIcon(new ImageIcon(About.class.getResource("/images/1326989302_icontexto-inside-facebook.png")));
		label.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JLabel label_1 = new JLabel("@pablosu");
		label_1.setIcon(new ImageIcon(About.class.getResource("/images/1326991198_icontexto-inside-linkedin.png")));
		label_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon(About.class.getResource("/images/1326990419_human-folder-development.png")));
		
		JLabel label_2 = new JLabel("@pablosu");
		label_2.setIcon(new ImageIcon(About.class.getResource("/images/1326989330_icontexto-inside-google.png")));
		label_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JLabel lblFiskisSvetis = new JLabel("Fiskis & Svettis Software Version 0.1");
		lblFiskisSvetis.setFont(new Font("Tahoma", Font.PLAIN, 23));
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.TRAILING)
				.addGroup(Alignment.LEADING, gl_contentPanel.createSequentialGroup()
					.addGap(41)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.TRAILING)
						.addComponent(lblDevelopByPablo)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPanel.createSequentialGroup()
									.addComponent(lblpablosu)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(label, GroupLayout.PREFERRED_SIZE, 112, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_contentPanel.createSequentialGroup()
									.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 112, GroupLayout.PREFERRED_SIZE)
									.addGap(18)
									.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 112, GroupLayout.PREFERRED_SIZE)))
							.addGap(18)
							.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 119, GroupLayout.PREFERRED_SIZE))
						.addGroup(Alignment.LEADING, gl_contentPanel.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(lblFiskisSvetis, GroupLayout.PREFERRED_SIZE, 375, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(28, Short.MAX_VALUE))
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblFiskisSvetis, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
					.addGap(25)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(label, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblpablosu))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
								.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)))
						.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 102, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
					.addComponent(lblDevelopByPablo))
		);
		contentPanel.setLayout(gl_contentPanel);
	}
}

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: