Comunidad PHPeros
Otros => Los Retos PHPeros => Mensaje iniciado por: Nasty35 en 18 de Abril de 2012, 16:05:01 pm
-
Estoy aprendiendo Java, y quiero que me hagan retos para mejorar lo aprendido, así como practicar.
Que no sea muy difícil, y sea de lógica o pensar...
Bueno, gracias y saludos ;)
-
Imprimir el código fuente de cualquier página web.
-
Imprimir el código fuente de cualquier página web.
Sinceramente eso no se como se hace ni haría,
¿Cómo se hace?
Dame otro reto :P no tan raro como ese.
-
Sinceramente eso no se como se hace ni haría,
¿Cómo se hace?
Dame otro reto :P no tan raro como ese.
Obtienes el contenido de una web y lo muestras como texto. Encima el tutorial circula por todo internet.
-
Sinceramente eso no se como se hace ni haría,
¿Cómo se hace?
Dame otro reto :P no tan raro como ese.
Mejor te pregunto, ¿qué sabes de Java?
-
Siento revivir tema pero no quiero crear otro, estuve leyendo libros y ya se más de Java.
Digan retos! creo que estoy listo para cualquier cosa :P
Preferiblemente algoritmos de pensar, y cosas así, no tocar mucho librerías ni cosas tipo mostrar código de fuente.
Lo de mostrar el código de fuente hice un programa hace unos meses, aquí dejo el código de fuente:
package codigodefuente;
import java.io.*;
import java.net.*;
import java.util.*;
/**
*
* @author Daniel
*/
public class CodigoDeFuente extends javax.swing.JFrame {
private URL url;
private URLConnection con;
private InputStream s;
private BufferedReader b;
private static Scanner sc;
public CodigoDeFuente() {
setTitle("Extrae la source de alguna página web.");
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
jTextField1 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("Mostrar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jScrollPane1.setViewportView(jTextPane1);
jTextField1.setText("http://");
jButton2.setText("Guardar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 470, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton2))
.addComponent(jScrollPane1))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
String link = jTextField1.getText();
try {
url = new java.net.URL(link);
con = url.openConnection();
s = con.getInputStream();
b = new BufferedReader(new InputStreamReader(s));
String line = "";
jTextPane1.setText(line);
while((line = b.readLine())!=null){
String code = jTextPane1.getText();
jTextPane1.setText(code + line + "\n");
} } catch (Exception e) {
e.printStackTrace();
}
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
String link2, link3;
String link = jTextField1.getText();
String tcode = jTextPane1.getText();
link2 = link.replace("http://","");
link3 = link2.replace("/","");
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(link3 + ".html"));
bw.append(tcode);
bw.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}//GEN-LAST:event_jButton2ActionPerformed
public static void main(String args[]) {
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(CodigoDeFuente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(CodigoDeFuente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(CodigoDeFuente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(CodigoDeFuente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CodigoDeFuente().setVisible(true);
}
});
sc = new Scanner(System.in);
String exi = sc.next();
switch(exi) {
case "Close":
case "close":
case "Cerrar":
case "cerrar":
System.exit(0);
default:
break;
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextPane jTextPane1;
// End of variables declaration//GEN-END:variables
}