|
Mostrar Mensajes
|
Páginas: [1]
|
1
|
Programación / Java / como convertir este jtable a excel o a pdf
|
en: 5 Junio 2013, 21:28 pm
|
Hola compañeros necesito su gran ayuda tengo una JTable pero al ingresar datos quiero que esos datos lo convierta a un archivo de excel o pdf no importa cual sea miren este es mi codigo import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.table.DefaultTableModel;
public class ventana2 extends JFrame implements ActionListener{ private JLabel e1 = new JLabel("Fecha de Registro"); private JLabel e2 = new JLabel( " Cloro"); private JLabel e3 = new JLabel("Ph"); private JLabel e4 = new JLabel(" Temperatura"); private JLabel e5 = new JLabel("Litros de Agua m³"); private JLabel e6 = new JLabel("numero de veces ingresados en la fila"); private JTextField t1 = new JTextField(55); private JTextField t2 = new JTextField(30); private JTextField t3 = new JTextField(30); private JTextField t4 = new JTextField(25); private JTextField t5 = new JTextField(25); private JTextField t6 = new JTextField(20); private JButton b1 = new JButton("Aceptar"); private JButton b2 = new JButton("Borrar fila"); private JScrollPane scroll; private JTable table = new JTable(); DefaultTableModel tabla = new DefaultTableModel(); String titulos[] = {"Fecha de Registro", "Cloro", "Ph", "Temperatura", "Litros de Agua m³"}; String datos[]= new String[5]; Integer fila, n, x; public ventana2(){ super("Tabla de registro"); this.setSize(800,400); this.setLayout(new FlowLayout()); this.setVisible(true); tabla.setColumnIdentifiers(titulos); table.setModel(tabla); table.setPreferredScrollableViewportSize(new Dimension(700,200)); scroll = new JScrollPane(table); add(e1); add(t1); add(e2); add(t2); add(e3); add(t3); add(e4); add(t4); add(e5); add(t5); add(e6); add(t6); add(b1); add(b2); add(scroll); b1.addActionListener(this); b2.addActionListener(this); }
@Override public void actionPerformed(ActionEvent e) { if(e.getSource()==b1){ datos[0]= t1.getText(); datos[1]= t2.getText(); datos[2]= t3.getText(); datos[3]= t4.getText(); datos[4]= t5.getText(); t1.setText(null); t2.setText(null); t3.setText(null); t4.setText(null); t5.setText(null); tabla.addRow(datos); t1.grabFocus(); n = tabla.getRowCount(); t6.setText(""+n); } else if(e.getSource()==b2){ fila = table.getSelectedRow(); if(fila>=0){ tabla.removeRow(fila); n = tabla.getRowCount(); t6.setText(""+n);
} else{ JOptionPane.showMessageDialog(null, "No ha seleccionado una fila.", "Error", JOptionPane.ERROR_MESSAGE); } } } } espero que me puedan ayudar
|
|
|
2
|
Programación / Java / ayuda como pasar informacion de un texto a un JTable
|
en: 1 Junio 2013, 22:13 pm
|
Hola compañeros solamente quiero saves como pasar de un texto a un Jtable desde un boton este es mi codigo que tengo mieren import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField;
public class ventana2 extends JFrame implements ActionListener {
private JLabel hp,pr,poh,pre,fech; private JTextField texto,texto3; private JLabel cantidad; private JTextField texto2,texto4; private JButton bt; private JLabel etiqueta; private String HP=""; JTable ventana2; public ventana2(){ super("ESTADISTICAS DEL PH"); this.setSize(750,500); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setVisible(true); setLayout(new FlowLayout()); cantidad=new JLabel("Nombre producto"); texto=new JTextField(50); hp=new JLabel( " Tamañp del producto"); texto2=new JTextField(50); texto3=new JTextField(58); texto4=new JTextField(58); pre=new JLabel(" Precio"); fech=new JLabel(" Fecha"); bt=new JButton(" Agregar Datos "); bt.setBackground(Color.gray); add(cantidad); add(texto); add(hp); add(texto2); add(pre); add(texto3); add(fech); add(texto4); add(bt); bt.addActionListener(this); this.setVisible(true); String[]columnNames={"PH","Cloro","cantidad","Fecha"}; Object [][] data = { {"","","",""}, {"","","",""}, {"","","",""}, {"","","",""},
}; { ventana2=new JTable(data,columnNames); ventana2.setPreferredScrollableViewportSize(new Dimension (700,250)); ventana2.setFillsViewportHeight(true); JScrollPane scrollPane=new JScrollPane(ventana2); add(scrollPane); }
}
@Override public void actionPerformed(ActionEvent e) {
}} }
necesito su ayuda gracias compañeros
|
|
|
4
|
Programación / Java / ayuda con factorialplis urge
|
en: 29 Mayo 2013, 03:24 am
|
hola compañeros me trabe en este programa es sobre un factorial lo que nesecito es que un jtexfiel me mande el resultado de del factorial a un jlebel desde un boton este es mi codigo import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JTextField;
import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import java.io.File; import java.io.FileWriter; import java.io.BufferedWriter;
public class FactorialH extends JFrame implements ActionListener { public static void main(String[] args) { FactorialH programa = new FactorialH(); programa.setVisible(true); }
private JLabel resultado; private JButton calcular; private JTextField numero;
public FactorialH() { super("Factorial"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setLayout(new FlowLayout()); setSize(400, 100); setVisible(true); resultado = new JLabel(); calcular = new JButton("Calcular"); numero = new JTextField(10); add(numero); add(resultado); add(calcular); calcular.addActionListener(this); }
private int factorial(int n) { if (n < 2) { return 1; } else { return n * factorial(n - 1); } }
@Override public void actionPerformed(ActionEvent arg0) { if (arg0.getSource() == calcular) { try { int miNumero = 0; miNumero = Integer.parseInt(numero.getText()); resultado.setText(String.valueOf(numero)); File archivo = new File("C:/Users/cedo/Desktop/archivo.txt"); try (FileWriter grabar = new FileWriter(archivo)) { BufferedWriter escribir = new BufferedWriter(grabar); escribir.write(resultado.getText()); escribir.flush(); escribir.close(); } } catch (Exception e) { numero.setText(""); resultado.setText(""); e.printStackTrace(); } } } } el problema cuando lo ejcuto no me sale nada ayudenme porfavor se los agradeceria
|
|
|
6
|
Programación / Java / Ayuda con el traductor de ingles a español plis
|
en: 18 Mayo 2013, 23:50 pm
|
hola compañeros soy nuevo con esto del netbeans y necesito todo de su ayuda porfavor de antemano estare agradecido con su gran ayuda Lo que pasa es que tengo un problema con este programa el cual quiero convertir de ingles a español y que al momento de marcar el boton traducir me tradusca la palabra y ademas poner un boton que al momento de apretarlo me borre los dos JTextField porfavor necesito ayuda les mostrare mi programa miren import java.awt.FlowLayout; import java.awt.event.*; import javax.swing.*;
public class traductor2_1 extends JFrame implements ActionListener{ private String world,cat,dog,file,name,age; private JLabel etiqueta1,etiqueta2; private JButton boton1,boton2; private JTextField texto1,texto2; public traductor2_1() { super("TRADUCTOR");} { setLayout(new FlowLayout()); setSize (300,200); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
etiqueta1=new JLabel("palabras en ingles"); texto1= new JTextField(15); etiqueta2=new JLabel("traduccion"); texto2= new JTextField(15); boton1=new JButton ("Aceptar"); boton2=new JButton("Borrar"); add(etiqueta1); add(texto1); add(etiqueta2); add(texto2); add(boton1); add(boton2); boton1.addActionListener(this); this.setVisible(true); }
@Override public void actionPerformed(ActionEvent e) { } espero su gran ayuda de antemano muchisimas gracias a todos por su ayuda
|
|
|
7
|
Programación / Java / ayuda traductor de ingles a español
|
en: 18 Mayo 2013, 02:41 am
|
hola necesito ayuda necesito borar el texto 1 y 2 con un boton borar pero no se como ayudenme porfavor este es mi codigo import java.awt.FlowLayout; import java.awt.event.*; import javax.swing.*;
public class traductor2_1 extends JFrame implements ActionListener{ private String world,cat,dog,file,name,age; private JLabel etiqueta1,etiqueta2; private JButton boton1,boton2; private JTextField texto1,texto2; public traductor2_1() { super("TRADUCTOR");} { setLayout(new FlowLayout()); setSize (300,200); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
etiqueta1=new JLabel("palabras en ingles"); texto1= new JTextField(15); etiqueta2=new JLabel("traduccion"); texto2= new JTextField(15); boton1=new JButton ("Aceptar"); boton2=new JButton("Borrar"); add(etiqueta1); add(texto1); add(etiqueta2); add(texto2); add(boton1); add(boton2); boton1.addActionListener(this); this.setVisible(true); }
@Override public void actionPerformed(ActionEvent e) { } }
|
|
|
10
|
Programación / Java / ayuda de netbeans de como convertir de dolares a pesos
|
en: 10 Mayo 2013, 03:15 am
|
hola compañeros necesito ayuda mi maestro me dejo hacer un programa de convertir de dolares a pesos pero con un menu este es mi codigo
import java.awt.event.*; import javax.swing.*;
public class tareah extends JFrame implements ActionListener{ private JMenuBar barra; private JMenu q1; private JMenuItem b1,b2; private JButton boton; public tareah() { super("Convertidor de monedas");} { setLayout (null); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setSize (400,400);
barra =new JMenuBar(); q1=new JMenu ("Cambio"); b1=new JMenuItem("D_P"); b2=new JMenuItem("Salir");
barra.add(q1); q1.add(b1); q1.add(b2);
this.setJMenuBar(barra); q1.addActionListener(this); setVisible(true); } @Override public void actionPerformed(ActionEvent e) { throw new UnsupportedOperationException("Not supported yet."); } }
necesito que en el menu el item D-P abra una nueva ventana y que tenga cantidad de dolares y el otro que diga convertido a pesos a y de paso en el menu como salir con la opcion del item espero su ayuda
|
|
|
|
|
|
|