diff --git a/src/Test.java b/src/Test.java deleted file mode 100644 index 129a658afc9160143c94d0748de2b4791c92b0a8..0000000000000000000000000000000000000000 --- a/src/Test.java +++ /dev/null @@ -1,3 +0,0 @@ -public class Test { - -} \ No newline at end of file diff --git a/src/myapp/MyApp.java b/src/myapp/MyApp.java new file mode 100644 index 0000000000000000000000000000000000000000..57e704ef909e644028308b4a7a4a449e1eaa46c5 --- /dev/null +++ b/src/myapp/MyApp.java @@ -0,0 +1,18 @@ +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); + } +} diff --git a/src/myapp/dao/MyEntityDao.java b/src/myapp/dao/MyEntityDao.java new file mode 100644 index 0000000000000000000000000000000000000000..c01f9eb2d09707ec30074b7bf6e9a7b7e2a9d440 --- /dev/null +++ b/src/myapp/dao/MyEntityDao.java @@ -0,0 +1,46 @@ +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 + } + } diff --git a/src/myapp/dao/MyEntityDaoTest.java b/src/myapp/dao/MyEntityDaoTest.java new file mode 100644 index 0000000000000000000000000000000000000000..0beba3528a22415205a002c1ce9a839dc08c5805 --- /dev/null +++ b/src/myapp/dao/MyEntityDaoTest.java @@ -0,0 +1,17 @@ +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 diff --git a/src/myapp/data/MyEntity.java b/src/myapp/data/MyEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..e635c4f729764212cbc318e601cb83425fc4f786 --- /dev/null +++ b/src/myapp/data/MyEntity.java @@ -0,0 +1,37 @@ +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; + } +} diff --git a/src/myapp/view/MyWindow.java b/src/myapp/view/MyWindow.java new file mode 100644 index 0000000000000000000000000000000000000000..e72c59b2b849519ebf241ac8f0b26e55bef918d3 --- /dev/null +++ b/src/myapp/view/MyWindow.java @@ -0,0 +1,35 @@ +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(); + } +}