Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Java concept ====== C++ Code --> Executable --> OS --> CPU Java code --> Class --> { "JVM win", "JVM linux", CPU that supports JAVA} --> OS --> CPU Java is like a application (Your Java app) running in another application (JavaVM). \\ so you need cmd java to run your app (.class)<code> javac yourJavaApp.java java youJavaApp</code> ====== Java tool, library and system environment path ====== * Java IDE list: * Eclipse (green): http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/indigosr1 * J2EE - for Enterprise system and application * J2SE - for desktop application * mostly used: http://www.oracle.com/technetwork/java/javase/downloads/index.html * then click download Java JDK, * for windows x86 direct link: http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-windows-i586.exe * idiot spoon feeding video guide if you're too lazy to google or youtube: http://www.youtube.com/watch?v=Hl-zzrqQoSE * J2ME - for micro and mobile application add java bin directory path to system environment or user profile environment variable: * for win dos <code dos> set path=c:\java\bin\location;%PATH%</code> * or go system property > environment variable > user variable : path; and add java location at end * for mac,linux <code bash> export path=/java/bin/location:$PATH</code> * or edit ~/.bash_profile, add this cmd line in it. ====== Portable Java JRE ====== - copy existing JRE to portable device - when use, in mac or linux terminal, <code>export JAVA_HOME=/jre_dir/bin/java export PATH=/jre_dir/bin:$PATH </code> and in dos <code>set path = %PATH%;d:\jre_dir\bin set JAVA_HOME=d:\jre_dir\bin\java </code> - force java use local JRE instead of asking system for it <code>java -verbose -jar MyApp.jar</code> ====== Quick Syntax ====== * Data type and access * String <code java>// compare string new String("test").equals("test") //==> true //ref: http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java </code> * Array (static type)<code java> int num[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; System.out.println("size of num[]: " + num.length); </code> * Dynamic array<code java>import java.util.ArrayList; private ArrayList<Item> items = new ArrayList<Item>(); System.out.println(items.size()); </code> * GUI * Layout <code java>FlowLayout() //FlowLayout.LEFT, FlowLayout.CENTER, FlowLayout.RIGHT, FlowLayout.LEADING, FlowLayout.TRAILING GridLayout(int rows, int columns) BorderLayout() BoxLayout() GroupLayout() SpringLayout() //ref: http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html </code> * JTable operation: * method list: http://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html * header update ref: http://www.roseindia.net/java/example/java/swing/ChangeColumnName.shtml * refresh header display after update <code java> listTable.getTableHeader().getColumnModel().getColumn(0).setHeaderValue("IC No"); listTable.getTableHeader().repaint(); //ref: http://www.java.net/node/692818 </code> * update date ref: http://stackoverflow.com/questions/5918727/updating-data-in-a-jtable * fill data <code java> for(int i=0;i<list.length;i++){ listTable.getModel().setValueAt(list[i].getICNO(), i, 0); listTable.getModel().setValueAt(list[i].getFirstName(), i, 1); listTable.getModel().setValueAt(list[i].getLastName(), i, 2); listTable.getModel().setValueAt(list[i].getTitle(), i, 3); listTable.getModel().setValueAt(list[i].getOrg(), i, 4); } </code> * clear data <code java> for (int i = 0; i < table.getRowCount(); i++) for(int j = 0; j < table.getColumnCount(); j++) { table.setValueAt("", i, j); } } </code> * user input * custom form dialog <code java>String[] n_arr=new String[3]; JTextField icno = new JTextField(); JTextField firstName = new JTextField(); JTextField lastName = new JTextField(); final JComponent[] inputs = new JComponent[] { new JLabel("IC NO"), icno, new JLabel("First Name"), firstName, new JLabel("Last Name"), lastName }; JOptionPane.showMessageDialog(null, inputs, "Member Creation", JOptionPane.PLAIN_MESSAGE); n_arr[0]=icno.getText(); n_arr[1]=firstName.getText(); n_arr[2]=lastName.getText(); </code> * Data validation for form guis * ref: http://www.codeproject.com/Articles/401805/A-framework-for-comprehensive-validation-of-user-i ====== Quick GUI dev and App dev with NetBean ====== * Quick GUI design guide from JFrame in NetBean (25 min) * http://netbeans.org/kb/docs/java/quickstart-gui.html * Quick App Build guide with user interaction (15 min) * http://netbeans.org/kb/docs/java/gui-functionality.html Some UI design Tips: * hide and show part of UI <code java> panelA.setVisible(false); //ref: http://www.codecommit.com/blog/java/techniques-of-java-ui-development </code> ====== Program Design Pattern ====== * MVC tips: * Calc example: http://leepoint.net/notes-java/GUI/structure/40mvc.html ====== Tutorials ====== * video: http://www.youtube.com/user/VoidRealms/playlists devwiki/java.txt Last modified: 2021/08/28 07:44by ying