Skip to content
Snippets Groups Projects
Commit 0cdf2916 authored by nilstes's avatar nilstes
Browse files

Added code

parent 045f1a03
No related branches found
No related tags found
No related merge requests found
public class Test {
}
\ No newline at end of file
package myapp;
import myapp.view.MyWindow;
/**
* Use this class to start the application
* @author nilstes
*/
public class MyApp {
/**
* Main method for my application
*/
public static void main(String[] args) throws Exception {
MyWindow window = new MyWindow("The Window");
window.setVisible(true);
}
}
package myapp.dao;
import myapp.data.MyEntity;
import java.util.Arrays;
import java.util.List;
/**
* DataAccessObject for the MyEntity-entity
*
* @author nilstes
*/
public class MyEntityDao {
/**
* Get object with given id
*
* @param id the entity id
* @return an instance of MyEntity
*/
public MyEntity getMyEntity(String id) {
// Get connection (maybe use pool?)
// Do some SQL
// Return som real data
return new MyEntity("id", "name");
}
public List<MyEntity> findMyEntities(String someParameter) {
// Get connection (maybe use pool?)
// Do some SQL
// Return som real data
return Arrays.asList(new MyEntity("id1", "name1"), new MyEntity("id2", "name2"));
}
public void addMyEntity(MyEntity obj) {
// Get connection (maybe use pool?)
// Do some SQL
}
public void deleteMyEntity(String id) {
// Get connection (maybe use pool?)
// Do some SQL
}
}
package myapp.dao;
import myapp.data.MyEntity;
import org.junit.Test;
import static org.junit.Assert.*;
public class MyEntityDaoTest {
@Test
public void testThatWeCanReadMyEntityFromDatabase() {
MyEntity e = new MyEntityDao().getMyEntity("id");
assertEquals(e.getName(), "name");
}
}
\ No newline at end of file
package myapp.data;
import java.util.Date;
import java.util.List;
/**
* This is just a simple Java-bean
* @author nilstes
*/
public class MyEntity {
private String id;
private String name;
public MyEntity() {
}
public MyEntity(String id, String name) {
this.id = id;
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
package myapp.view;
import myapp.dao.MyEntityDao;
import myapp.data.MyEntity;
import java.awt.GridLayout;
import javax.swing.*;
/**
* Main window for my application!
*
* @author nilstes
*/
public class MyWindow extends JFrame {
/**
* Constructor for window
*
* @param title Title ow the window
* @return the image at the specified URL
* @see Image
*/
public MyWindow(String title) {
super(title);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLayout(new GridLayout(1, 1, 1, 1));
MyEntityDao dao = new MyEntityDao();
MyEntity object = dao.getMyEntity("id");
add(new JLabel(object.getName()));
pack();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment