Advance codes

Imal Hasaranga perera

png like this path starts from source package so the image should be in the souce package (default pagckage) . Date y1 = dateFormat.out.DEFAULT_OPTION.showMessageDialog(null. options. // date format Converting a string to a date object using dateformat method DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd").setIcon(icon).getTime(). JOptionPane. "Are You Sure You want to Proceed".pars(y). "Warning". if image is in a different package u can use /packagename/warning_64.Getting a image from a URL and setting it to a label ImageIcon icon = new ImageIcon("E:/warning_64. String = dateFormat. options[0]). Getting the time from milliseconds Date d1 = new Date(). // creating a new date object DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd").png". "click"). "CANCEL" }.null.showOptionDialog(null.png Working with the time Date d1 = new Date(). Warning massage dialog box Object[] options = { "YES".JOptionPane. if(respon==0){ System. int respon = JOptionPane. Formatting a Date according to a format DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd").format(new Date()).WARNING_MESSAGE. } Imal Hasaranga perera . ""). Long x = d1. you can use relative path /warning_64. String y = "2008/12/21".println( this is YES ). Massage dialogs Normal massage dialog JOptionPane. jLabel1.

stmt. String sql = "insert into students(studentpic. Statement st = con.createStatement(). Imal Hasaranga perera . File f = new File(fName).length()]. Connection con = DB.wav". } } Sql Queries Sql query to get the last row SELECT * FROM users ORDER BY userid DESC LIMIT 1 Sql inner queries (nested queries ) SELECT Model FROM Product WHERE ManufacturerID IN (SELECT ManufacturerID FROM Manufacturer WHERE Manufacturer = 'Dell') Sql query example to use logics select* from project where (ProjectType = '"+Type+"')&&(RequestID = '"+RequesId1+"') Adding a image to Database using prepared statement(sql data type should set to blob) String fName = "C:/Documents and Settings/PC/My Documents/My Pictures/birthday-cat. AudioPlayer.out. } catch (Exception e) { System.start(audioStream).?)".player.Playing a sound track (plays a sound using url of the track) try { String gongFile = "E:/ values(?. PreparedStatement stmt = (PreparedStatement) con. try { in = new FileInputStream(f).getMyConnection().println(e). byte[] image = new byte[(int) f. AudioStream audioStream = new AudioStream(in).prepareStatement(sql). FileInputStream in. in.setBytes(1. image).jpg". InputStream in = new FileInputStream(gongFile).read(image).

out. stmt. byte[] plainText = password. l1. } System. StringBuilder sb = new StringBuilder(). MessageDigest md = null.out. ImageIcon icon = new ImageIcon(b.MessageDigest. } } Imal Hasaranga perera .getBytes(1L. i++) { if ((encodedPassword[i] & 0xff) < 0x10) { sb.getInstance(algorithm).getText()). stmt.stmt.update(plainText). id. (int) b. } Retriving image from Database Blob b = (Blob) rs. i < encodedPassword.setIcon(icon). md. } md.executeUpdate(). Password encrypt import System.length())).toString(encodedPassword[i] & 0xff.println("Plain : " + password). } sb. public class EncryptExample { public static void main(String[] args) { String password = "secret".close(). for (int i = 0.println("Encrypted: " + sb. } catch (Exception e) { System. try { md = MessageDigest. String algorithm = "SHA".length.println(e+"gg").reset().setString(2.append("0"). 16)).digest().getBlob("image"). byte[] encodedPassword = md. } catch (Exception e) { e.printStackTrace().

equals(evt. int i = s. } } } } catch (Exception e) { System.out.equals("ApproveSelection")) { File file = jFileChooser1.add("a"). String s = file.createLineBorder(Color.getActionCommand())) { this.showMessageDialog(null.println(file).CANCEL_SELECTION. Selecting a image file from a jfile Chooser(code inside of the action performe of the jfeile chooser ) try { if (JFileChooser.println( this is a image file ). System.setBorder(BorderFactory. "please select a valid file type").out.println("dffdfd"). Adding data al.setVisible(false).getName().Using java runtime methord Runtime.getRuntime().equals(extension) || "jpg". Setting border of a image by code Jlabel1.1) { String extension = s.out.').equals(extension)) { System.lastIndexOf('. } if (evt.FileProtocolHandler C:/Windows/imal.toLowerCase(). if (i > 0 && i < s.substring(i + 1).dll.equals(extension) || "png". Removing data Imal Hasaranga perera .pdf ).exec("rundll32 url.getActionCommand().black)).add("b").getSelectedFile(). if ("tiff".equals(extension) || "jpeg". } else { JOptionPane. al.equals(extension) || "gif". } Creating an unlimited Array (Array list) Creating the array ArrayList al = new ArrayList().length() .

getting elements out Object a[] = al. .etc Just implement keylistener to your frame. . System. .} public void keyReleased(KeyEvent e){.setFocusable(true).} public void keyTyped(KeyEvent e) } {. . . Absolute path this.getProperty("user.println(String. way you can call the focuse again to the frame if you click a button on frame using mouse class MyPanel extends JPanel implements KeyListener { .remove("F"). . panel and do like this way And by this.valueOf(a[0])).getResource("zero.getClass().al. . // Allow this panel to get focus.Define one or more of these to handle keyboard events public void keyPressed(KeyEvent e) {. . } //-. Java ternary operator example int d = a<b ? a:b. .remove(2).addKeyListener(this). al.requestFocusInWindow().out.toString() System.toArray().} Imal Hasaranga perera . // listen to our own key events. //=================================== constructor public MyPanel() { this. this. .dir") + "/src/" + path Keybord key events when no text fields . .au").

wordpress.htm Imal Hasaranga perera .Jasper notes you can get from http://record-editor.4 http://ireport.

Sign up to vote on this title
UsefulNot useful