Pasar de delphi a java

Páginas: 6 (1297 palabras) Publicado: 18 de enero de 2012
EQUIVALENCIAS DELPHI/JAVA
ÍNDICE
inherited setFocus OnClick keyPressed Atajo de teclado en menú (shortcuts) TImage inc Terminate hint ShowMessage Look & Feel JTextArea Jscroll y JTextArea jMenu jTabbedPane ArrayList Archivos con streams de objetos Archivos de texto orientados a líneas Archivos binarios Streams y Buffers Gestión de eventos (dos formas) Timers Threads Sockets ServerSockets AppletCONTENIDOS

inherited super() setFocus setFocus = jCBletra.requestFocusInWindow(); OnClick Simular OnClick: Button.doClick(); keyPressed keyPressed public void keyPressed(java.awt.event.KeyEvent e) { if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) { …........... } } Atajo de teclado en menú (shortcuts) jMenu.setMnemonic('M'); TImage No existe equivalente del componente TImage ni enawt ni swing. Lo más cómodo es usar jLabel. JLabel.setIcon(new javax.swing.ImageIcon("0.png")); inc inc(x) en java: x++ o bien ++x si se quiere incrementar antes o después de una operación. Ejemplo: ++x*2 suma 1 y luego multiplica por dos. terminate application.terminate; = System.exit(0); //Finalización sin error hint toolTipText ShowMessage javax.swing.JOptionPane.showMessageDialog(this,e.getMessage()); Look & Feel int current =0; private void cambiarLook(String look) { try {

UIManager.setLookAndFeel(look); SwingUtilities.updateComponentTreeUI(this); } catch (Exception exception) { javax.swing.JOptionPane.showMessageDialog(this, exception.getMessage()); } } //Cambia al siguiente look cambiarLook(UIManager.getInstalledLookAndFeels()[current++ %UIManager.getInstalledLookAndFeels().length].getClassName()); //Cambia al look motif cambiarLook("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); com.sun.java.swing.plaf.gtk.GTKLookAndFeel com.sun.java.swing.plaf.motif.MotifLookAndFeel com.sun.java.swing.plaf.windows.WindowsLookAndFeel "javax.swing.plaf.mac.MacLookAndFeel" JTextArea Métodos útiles: jTextArea.setEditable(false); //No editable jTextArea.setLineWrap(true); //Ajusta eltexto sin desbordar el lateral jTextArea.setWrapStyleWord(true); //No rompe palabras al ajustar jTextArea.append("Linea texto\n"); //Añade texto //Para desplazar hasta el final del cuadro: jTextArea.setCaretPosition(jTextArea.getDocument().getLength()); jTextArea.setFont(font); //Asigna fuente jTextArea.setForeground(Color.red); //Cambia color de tipo de letra

Jscroll y JTextArea EngetJContentPane añadir: JScrollPane scroll = new JScrollPane(jTextArea); jContentPane.add(scroll, gridBagConstraints);

jMenu Separador de menuItems: menu.addSeparator(); jTabbedPane Los contenedores de cada pestaña son JPanel. getSelectedComponent: Devuelve en panel de la pestaña activa. getSelectedIndex: Devuelve el nº de pestala activa. Archivos con streams de objetos

FileOutputStream fos = newFileOutputStream(“Fechas.txt"); ObjectOutputStream s = new ObjectOutputStream(fos); s.writeObject(“Hoy"); s.writeObject(new Date()); s.flush(); s.close(); Ejemplo 3: try { //Construct the ObjectInputStream object inputStream = new ObjectInputStream(new FileInputStream(filename)); Object obj = null; while ((obj = inputStream.readObject()) != null) { if (obj instanceof Person) {System.out.println(((Person)obj).toString()); } }

} catch (EOFException ex) { //This exception will be caught when EOF is reached System.out.println("End of file reached."); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } finally { //Close the ObjectInputStream try { if (inputStream != null) {inputStream.close(); } } catch (IOException ex) { ex.printStackTrace(); } }

}

Archivos de texto orientados a líneas Las lecturas y escrituras deben estar protegidas en un try/catch LECTURA:
File archivo = new File ("C:\archivo.txt"); FileReader fr = new FileReader (archivo); BufferedReader br = new BufferedReader(fr); ... String linea = br.readLine();

ESCRITURA:
FileWriter fichero = new...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Primeros pasos en Java.
  • pasos para instlar java
  • Pasos Para La Instalación Del Compilador De Java
  • Herencia en java paso a paso
  • CU00602B Orientacion Curso Paso A Paso Aprender A Programar En Java
  • Delphi
  • javiera y valde pas
  • Delphi

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS