|
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.awt.event.*;
import java.net.*;
import javazoom.jl.player.*;
class Myjpanel extends JPanel implements ActionListener,Runnable
{
boolean count=true;
Thread th;
JSlider js1;
JLabel jl;
private JButton jb1,jb2;
JTextField jt1;
public SoundJLayer soundToPlay;
public Myjpanel()
{
jl=new JLabel(" ");
jb1=new JButton("Open");
jb2=new JButton("Stop");
jt1=new JTextField(20);
js1=new JSlider(1,100);
add(jt1);
this.add(jb1);
this.add(jb2);
add(js1);
js1.setValue(0);
js1.setPaintLabels(false);
jb1.addActionListener(this);
jb2.addActionListener(this);
this.add(jl);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jb2)
{
count=true;
soundToPlay.stop1();
jl.setText(" 0 : 0 ");
}
else
{
th=new Thread(this);
if(count==true)
{
JFileChooser jfc=new JFileChooser();
File f=null;
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
int choice=jfc.showOpenDialog(null);
if(choice!=JFileChooser.CANCEL_OPTION)
{
f=jfc.getSelectedFile();
}
if(f==null)
JOptionPane.showMessageDialog(null,"You didn't select a file");
else
{
int option=JOptionPane.showConfirmDialog(null,"You selected "+f.getName()+"\nDo you want to open it?");
if(option==JOptionPane.YES_OPTION)
{
String str=f.getName();
jt1.setText(str);
soundToPlay= new SoundJLayer(f);
soundToPlay.play();
th.start();
count=false;
}
}
}
}
}
public void run()
{
int i=0;
for(;count==false;)
{
try
{
Thread.sleep(1000);
}
catch(InterruptedException ex)
{
}
double db1=soundToPlay.player.getPosition();
int db=(int)db1/1000;
js1.setValue(db);
db=db%60;
if(db==59)
i++;
String str1=String.valueOf(i);
String str=String.valueOf(db);
jl.setText(str1+" : "+str);
}
}
}
class Myjframe extends JFrame
{
private Myjpanel jp;
public Myjframe(String title)
{
super(title);
jp=new Myjpanel();
Container ct=getContentPane();
ct.add(jp);
setVisible(true);
setBounds(50,50,200,200);
setDefaultCloseOperation
(JFrame.EXIT_ON_CLOSE);
}
}
public class mymp3player2
{
public static void main(String[] args)
{
Myjframe obj=new Myjframe("Sumit's");
}
}
class SoundJLayer implements Runnable
{
public Player player;
public Thread playerThread;
private URL url;
public SoundJLayer(File file)
{
try
{
url=file.toURL();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public void play()
{
try
{
InputStream ip=url.openStream();
this.player = new Player(ip);
this.playerThread = new Thread(this, "AudioPlayerThread");
this.playerThread.start();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public void run()
{
try
{
this.player.play();
}
catch (javazoom.jl.decoder.JavaLayerException ex)
{
ex.printStackTrace();
}
}
public void stop1()
{
this.player.close();
}
}
|
|
|
|
|
1. Pleas indent your code and put it between <pre> tags for readability, thus
public void stop1()
{
this.player.close();
}
2. Give proper details of your problem.
Use the best guess
|
|
|
|
|
when i play an mp3 file then if i want to pause that song for some time then i can't i can only play and stop the song in this code
|
|
|
|
|
Rather than just repeating your original post, it would be helpful if you followed my previous suggestions. It is extremely difficult to read your code from that unformatted listing, and I cannot find a method anywhere that handles a Pause command.
Use the best guess
|
|
|
|
|
I'm getting two values for my salt
This is my code
private static String getSalt() throws NoSuchAlgorithmException, NoSuchProviderException
{
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
byte[] salt = new byte[8192];
sr.nextBytes(salt);
return salt.toString();
}
and when I save it in my database
my code
PS.setString(1, User);
PS.setString(2, getSalt());
PS.executeUpdate();
System.out.println(" Salt :"+getSalt());
I get different value..why?
I'm salting String asdf
Database value [B@2fc396df
Printed value [B@5199c9ac
|
|
|
|
|
salt.toString();
That doesn't do what you think it does. It prints the object reference not the contents.
|
|
|
|
|
By the way, your function createSalt() creates a new salt every time you call it!
When you want to compare the original value and the database value, you hat to write the salt into a variable, then set it to your object, write to database, then retrieve from the database.
|
|
|
|
|
public void run(){
for(int i=0;i<totalThread;++i){
Thread x=new Thread(new RequestProcessor(documentRootDirectory,indexfileName));
x.start();
}
System.out.println("coonection accepted"+server.getLocalPort());
System.out.println("Dokumen root"+documentRootDirectory);
while(true){
try{
Socket request=server.accept();
RequestProcessor.startProcessing();
}
catch(IOException ex){
}
}
}
error message from this program : method RequestProcessor can't not implemented with given types,
althaugh i have create class RequestProcessor from one package, can you help me to integrated the totalThread with RequestProcessor? the error start when i try to instance new Thread.
thx.
|
|
|
|
|
|
How to read this XML file:
I need to read attribute name/value pair and element contents.
="1.0"="UTF-8"
<idmef:IDMEF-Message xmlns:idmef="http://iana.org/idmef" version="1.0">
<idmef:Alert messageid="abc123456789">
<idmef:Analyzer analyzerid="bc-sensor01">
<idmef:Node category="dns">
<idmef:name>sensor.example.com</idmef:name>
</idmef:Node>
</idmef:Analyzer>
<idmef:CreateTime ntpstamp="0xbc71f4f5.0xef449129">2000-03-09T10:01:25.93464Z</idmef:CreateTime>
<idmef:Source ident="a1a2" spoofed="yes">
<idmef:Node ident="a1a2-1">
<idmef:Address ident="a1a2-2" category="ipv4-addr">
<idmef:address>192.0.2.200</idmef:address>
</idmef:Address>
</idmef:Node>
</idmef:Source>
<idmef:Target ident="b3b4">
<idmef:Node>
<idmef:Address ident="b3b4-1" category="ipv4-addr">
<idmef:address>192.0.2.50</idmef:address>
</idmef:Address>
</idmef:Node>
</idmef:Target>
<idmef:Target ident="c5c6">
<idmef:Node ident="c5c6-1" category="nisplus">
<idmef:name>lollipop</idmef:name>
</idmef:Node>
</idmef:Target>
<idmef:Target ident="d7d8">
<idmef:Node ident="d7d8-1">
<idmef:location>Cabinet B10</idmef:location>
<idmef:name>Cisco.router.b10</idmef:name>
</idmef:Node>
</idmef:Target>
<idmef:Classification text="Ping-of-death detected">
<idmef:Reference origin="cve">
<idmef:name>CVE-1999-128</idmef:name>
<idmef:url>http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-1999-128</idmef:url>
</idmef:Reference>
</idmef:Classification>
</idmef:Alert>
</idmef:IDMEF-Message>
|
|
|
|
|
I showed you how to find information on reading CSV files, no doubt you can do the same for XML.
Use the best guess
|
|
|
|
|
I know how to read xml file but I have a problem with this file.
|
|
|
|
|
peniya wrote: I know how to read xml file but I have a problem with this file. Then you need to explain what that problem is; please don't expect people to guess it.
Use the best guess
|
|
|
|
|
How to write this code?
I have .csv file. Content of file like as follow:
A,B
B,C
A,F
F,G
G,H
B,D
I have to read this file and output should be :
A _ B _ C
| |_ D
|_F _ G_ H
How to write this code to get this output?
modified 30-Jul-13 12:41pm.
|
|
|
|
|
peniya wrote: I have to use swing You don't use swing to read a file. Look at these links[^].
Use the best guess
|
|
|
|
|
For output I should use swing.
and I know how to read .csv file, but my problem is with output.
how to get that output.
|
|
|
|
|
That question is impossible to answer in a forum like this. Go and find some swing tutorials and learn about what features are available to hlep you format your output.
Use the best guess
|
|
|
|
|
hi i have problem selecting the numbers that is not in the single/double qoutes . let say we have this text below .
123
<style color="#767676">
8787
i want to select just the 123 and 8787 , nothing else
how should i do this with regular expression in javascript
|
|
|
|
|
|
private static void insertRecord() throws SQLException
{
Connection con = null;
Statement statement = null;
try
{
PreparedStatement PS = Connectionstring().prepareStatement("INSERT INTO LoginDetails(Username,Password) VALUES (?,?)");
String User = tf_Uname.getText();
String _Pass = new String(tf_pass.getPassword());
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-256");
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
md.update(_Pass.getBytes());
byte byteData[] = md.digest();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < byteData.length; i++) {
sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
}
System.out.println("Hex format : " + sb.toString());
StringBuffer hexString = new StringBuffer();
for (int i=0;i<byteData.length;i++)
{
String hex=Integer.toHexString(0xff & byteData[i]);
if(hex.length()==1) hexString.append('0');
hexString.append(hex);
}
System.out.println("Hex format : " + hexString.toString());
PS.setString(1, User);
PS.setString(2, _Pass);
PS.executeUpdate();
JOptionPane.showMessageDialog(null,"Your Data has been Inserted","Data Inserted",JOptionPane.INFORMATION_MESSAGE);
}
catch (SQLException e)
{
System.out.println(e.getMessage());
}
finally
{
if (statement != null)
{
statement.close();
JOptionPane.showMessageDialog(null,"Statement is closed","Statement",JOptionPane.INFORMATION_MESSAGE);
}
if (con != null)
{
con.close();
JOptionPane.showMessageDialog(null,"Connection is closed!","Connection",JOptionPane.INFORMATION_MESSAGE );
}
}
}
I'm getting the right output but could not able to save the hash password into the database it's being stored as a Text.
|
|
|
|
|
Hello chdboy please check this line
PS.setString(1, User);
PS.setString(2, _Pass);
PS.executeUpdate();
you have provided normal text to user and password field
While you need to provide hex code in this line no 1 and 2
|
|
|
|
|
Thanks a lot ...now let's see if there is a problem in getting hex code back to the string when user enter details .
|
|
|
|
|
You shouldn't need to, that means anyone else can, and your system is not secure. Passwords should use one-way hashes so they can never be converted back to the original string. See Secure Password Authentication Explained Simply[^].
Use the best guess
|
|
|
|
|
I am new to Java and Web Development. I need to build a Java server App, which has to interact with MySQL DB stored procedures and fetch rows and return to client.
1. Client can be from Http request from web browser
2. An Android app
3. Desktop app
4. and others
Now my question is; should the server App be
1.JSP
2.Servlet
3.WebService
Load balancing should be done for Server App, and server App is going to be 3-tire
Please advice the Pro/Cons in each case.
|
|
|
|
|
This question is far too broad for a technical forum such as this. You need to do your own research and study before deciding which technologies will be best to address your problem.
Use the best guess
|
|
|
|