Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
combine int and string Posted by dinga94 on 7 Dec 2010 at 2:09 AM
hi all,
using netbeans with mySQL. how can i cobime data from two tables to get and entry on third column eg
table one called patients has
IDint(auto primary),patient_name(string),patient_numb(string).
on my GUI
enter name eg smith
i want this to be generated Smi-0001
0001 being the IDint
i can achieve this in eclipse but don't know how to go about it in netbeans environment; if u run this u c what i mean ...
package utils;

import java.awt.Container;

import javax.swing.*;
import java.awt.event.*;
import java.text.DecimalFormat;

public class CombineFields extends JFrame implements ActionListener{

private static final long serialVersionUID = 1L;

private JTextField txtRegion,txtId_number,txtResult ;
private JLabel lblRegion, lblId_number, lblResult;
String reg, id ,temp_reg, temp_result, dash = "-" ;
double temp_id, to_deci = 0.00001;

public CombineFields(){

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Generate work number");

Container cont = getContentPane();
cont.setLayout(null);

lblRegion = new JLabel("Region: ",SwingConstants.RIGHT);
lblId_number = new JLabel("Id Numb: ",SwingConstants.RIGHT);
lblResult = new JLabel("WorkNumb: ",SwingConstants.RIGHT);

txtRegion = new JTextField();
txtId_number = new JTextField();
txtResult = new JTextField();

txtResult.setEditable(false);


cont.add(lblRegion);
cont.add(txtRegion);
cont.add(lblId_number);
cont.add(txtId_number);
cont.add(lblResult);
cont.add(txtResult);

txtId_number.addActionListener(this);

lblRegion.setBounds(10,40,90,25);
txtRegion.setBounds(100,40,90,25);
lblId_number.setBounds(10,80,90,25);
txtId_number.setBounds(100,80,90,25);
lblResult.setBounds(10,120,90,25);
txtResult.setBounds(100,120,90,25);

setSize(300,350);
setVisible(true);

}

public void actionPerformed(ActionEvent event){

DecimalFormat precision = new DecimalFormat( "0.00000" );

reg = txtRegion.getText();
temp_reg = reg.substring(0,3);
temp_reg = temp_reg.concat(dash);

id = txtId_number.getText();
temp_id = Integer.parseInt(id);

to_deci = to_deci * temp_id;
String shortString = (precision.format(to_deci));
temp_result = shortString.substring(2);
temp_reg = temp_reg.concat(temp_result);
txtResult.setText(temp_reg);

}

public static void main(String args[]){

new CombineFields();

}


}

any help pls.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.