|
I am also understanding Java using
Java How To
-=Dietel=-
|
|
|
|
|
Hello! I Could Print Contents of Java JTable using Printer using the following Code:
MessageFormat header=new MessageFormat("Printing JTable Contents");
MessageFormat foot = new MessageFormat("Page(0,number,integer)");
try {
JTable1.print(JTable.PrintMode.NORMAL, header, foot);
}
catch (java.awt.print.PrinterException e) {
System.err.format("Error! Cannot Print. ", e.getMessage());
}
But, I Couldn't Print All Contents of Java JTextFields and JLabels Only on Form using Printer. Can Some One help me how to print all contents of JTextFields and their corresponding JLabels???? Thanks!!!
|
|
|
|
|
|
Hello! I was trying to print contents in JText Fields and their corresponding JLabels on paper using the following code:
Toolkit tkp = jPanel7.getToolkit();
PrintJob pjp = tkp.getPrintJob(this, null, null);
Graphics g = pjp.getGraphics();
jPanel7.printAll(g);
g.dispose();
pjp.end();
But it's not printing the contents; It only prints all visible components on the jPanel7.
Please try modifying the code so as to print contents of text fields and their corresponding labels only???
Thanks!!!
|
|
|
|
|
The documentation[^] statest that printAll will invoke print which will then cause the panel and all its constituent parts to be printed. I would suggest you use your debugger to try and discover why this is not working in your case.
Veni, vidi, abiit domum
|
|
|
|
|
Wow Great!!! Problem Solved! It's working properly now!!! What I did is that I included all components to be printed(which are jLabels) in one jPanel and components not required in an other jPanel; I retrieved the data in DB to the jLabels and I call the jPanel containing my jLabels using the code I posted as question.
Thanks!!!
|
|
|
|
|
Hello
I'm new to programming and I'm trying to make a java application that will "hear" (not record necessarily) the sound and display how loud is.I'm thinking of converting the sound recordings to numbers,so I can see the difference on the sound levels.I got this code and I added the "getLevel()" method,which returns the amplitude of the current recording,but it's returning -1 everytime.I guess I'm not using it properly. Any ideas how I must call this method?I have to deliver my project in a week,so any help will be much appreciated!
public class Capture extends JFrame {
protected boolean running;
ByteArrayOutputStream out;
public Capture() {
super("Capture Sound Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container content = getContentPane();
final JButton capture = new JButton("Capture");
final JButton stop = new JButton("Stop");
final JButton play = new JButton("Play");
capture.setEnabled(true);
stop.setEnabled(false);
play.setEnabled(false);
ActionListener captureListener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
capture.setEnabled(false);
stop.setEnabled(true);
play.setEnabled(false);
captureAudio();
}
};
capture.addActionListener(captureListener);
content.add(capture, BorderLayout.NORTH);
ActionListener stopListener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
capture.setEnabled(true);
stop.setEnabled(false);
play.setEnabled(true);
running = false;
}
};
stop.addActionListener(stopListener);
content.add(stop, BorderLayout.CENTER);
ActionListener playListener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
playAudio();
}
};
play.addActionListener(playListener);
content.add(play, BorderLayout.SOUTH);
}
private void captureAudio() {
try {
final AudioFormat format = getFormat();
DataLine.Info info = new DataLine.Info(
TargetDataLine.class, format);
final TargetDataLine line = (TargetDataLine)
AudioSystem.getLine(info);
line.open(format);
line.start();
Runnable runner = new Runnable() {
int bufferSize = (int)format.getSampleRate()
* format.getFrameSize();
byte buffer[] = new byte[bufferSize];
public void run() {
out = new ByteArrayOutputStream();
running = true;
try {
while (running) {
int count =
line.read(buffer, 0, buffer.length);
if (count > 0) {
out.write(buffer, 0, count);
System.out.println(line.getLevel());
}
}
out.close();
} catch (IOException e) {
System.err.println("I/O problems: " + e);
System.exit(-1);
}
}
};
Thread captureThread = new Thread(runner);
captureThread.start();
} catch (LineUnavailableException e) {
System.err.println("Line unavailable: " + e);
System.exit(-2);
}
}
private void playAudio() {
try {
byte audio[] = out.toByteArray();
InputStream input =
new ByteArrayInputStream(audio);
final AudioFormat format = getFormat();
final AudioInputStream ais =
new AudioInputStream(input, format,
audio.length / format.getFrameSize());
DataLine.Info info = new DataLine.Info(
SourceDataLine.class, format);
final SourceDataLine line = (SourceDataLine)
AudioSystem.getLine(info);
line.open(format);
line.start();
Runnable runner = new Runnable() {
int bufferSize = (int) format.getSampleRate()
* format.getFrameSize();
byte buffer[] = new byte[bufferSize];
public void run() {
try {
int count;
while ((count = ais.read(
buffer, 0, buffer.length)) != -1) {
if (count > 0) {
line.write(buffer, 0, count);
}
}
line.drain();
line.close();
} catch (IOException e) {
System.err.println("I/O problems: " + e);
System.exit(-3);
}
}
};
Thread playThread = new Thread(runner);
playThread.start();
} catch (LineUnavailableException e) {
System.err.println("Line unavailable: " + e);
System.exit(-4);
}
}
private AudioFormat getFormat() {
float sampleRate = 8000;
int sampleSizeInBits = 8;
int channels = 1;
boolean signed = true;
boolean bigEndian = true;
return new AudioFormat(sampleRate,
sampleSizeInBits, channels, signed, bigEndian);
}
@SuppressWarnings("deprecation")
public static void main(String args[]) {
JFrame frame = new Capture();
frame.pack();
frame.show();
}
}
modified 9-Dec-13 6:47am.
|
|
|
|
|
The documentation for getLevel [^] suggests that -1 means that no value can be obtained, or that it has not been set. It is difficult to suggest anything that would help solve this issue, but maybe you should use your debugger to try and collect some more information.
Veni, vidi, abiit domum
|
|
|
|
|
Do you have any suggestion on another way that I could get the amplitude of the sound?
|
|
|
|
|
I'm afraid not, I do not have experience of these classes. Did you write all this code yourself, and if so, what reference guides or tutorials did you use?
Veni, vidi, abiit domum
|
|
|
|
|
No,I've found the complete code and I'm trying to modify it to do some more things that I need for my project.If you have a better piece of code to suggest me,feel free to do it
|
|
|
|
|
xchris00 wrote: No,I've found the complete code and I'm trying to modify it As I said before, I have not used these classes, so I guess you need to go back to the place where you found it originally and seek help there.
Veni, vidi, abiit domum
|
|
|
|
|
|
Ok,I managed to make it capture audio and print on a xls file the timestamp and the value of the current sample,but there is a problem : even I've put some spaces between the time and the value and it seems that they are in different columns,they are actualy on the same column of the xls,it's just expanded and covers the next column (I can put a print screen if you don't understand).How can I make it print the data of time and amplitude in two different columns?Here's my code of the class which creates the file and saves the data on xls :
package soundRecording;
import java.io.File;
import java.util.Formatter;
public class Save {
static Formatter y;
public static void createFile() {
Date thedate = new Date();
final String folder = thedate.curDate();
final String fileName = thedate.curTime();
try {
String name = "Time_"+fileName+".csv";
y = new Formatter(name);
File nof = new File(name);
nof.createNewFile();
System.out.println("A new file was created.");
}
catch(Exception e) {
System.out.println("There was an error.");
}
}
public void addValues(byte audio) {
Date d = new Date();
y.format("%s " + " %s%n",d.curTime(), audio);
}
public void closeFile() {
y.close();
}
}
|
|
|
|
|
I want to draw bezier cubic curves by retrieving data from MySQL database and then display the shape on JFrame I have table has 3 columns (ID, ObjectID, Points) Points column is coordinates of cubic curves, the statement is
SELECT * FROM DB.TABNAME WHERE OBJECTID=1; ObjectID=1 has 11 ID's, each ID contains a shape if i combine all ID`s together will form composite shape How can i retrieve data from MySQL database, that data are path to draw bezier cubic curves in java GUI?
modified 9-Dec-13 5:36am.
|
|
|
|
|
ابو عبدالله wrote: How can i retrieve data from MySQL database Read all records and build a collection of the points as you read them; as I suggested in my previous answer[^].
Veni, vidi, abiit domum
|
|
|
|
|
can I convert a string token into a char array or string array
|
|
|
|
|
At best the question is not precise.
A "string token" doesn't mean anything in terms of the java language.
Now you might write a program that uses a "string token" but in general computer science jargon a "token" is a small non-dividable entity. There would be no point in converting it to a char array and even less point of creating a string array from it. And at best the latter would be nothing more than taking each character and making it into a string.
But then you might mean something different for "string token". If so you need to explain what you actually meant.
|
|
|
|
|
Have a look at String.toCharArray() ? See here[^]
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
so please tell me about that source code about that main window in auto mobile spare part in java project
|
|
|
|
|
Read the forum guidelines again, and try a more specific question. If you want source code then you need to search with Google, Bing etc.
Veni, vidi, abiit domum
|
|
|
|
|
Member 10449243 wrote: so please tell me about that source code about that main window in auto mobile spare part in java project
You do this in the following order
1 - Gather requirements, figure out what the 'main' window does.
2 - Learn basic java programming
3 - In general learn about web/internet server functionality how it works (presumably that is the goal)
4 - Learn the basics of implementing a web application in java
5 - Probably will need to learn about databases and how to access them in java
6 - Starting with 1, use what you learned in 2-5 to implement a java solution.
7 - Test it until there are no more bugs (or ones you can live with.)
|
|
|
|
|
tell me any advice about the mcs studies and how i can make my self good in developing
|
|
|
|
|
|
I'm not able to see content on JFrame ,when JFrame shows up.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class GraphicUse extends JPanel
{
public void PaintComponent(Graphics gr)
{
super.paintComponents(gr);
this.setBackground(Color.BLUE);
gr.setColor(Color.WHITE);
gr.fillRect(50, 50, 100, 100);
gr.setColor(new Color(139,38,190));
gr.fillRect(50, 70, 100, 100);
gr.setColor(Color.RED);
gr.drawString("This is a new String", 50, 90);
}
public static void main(String[] args)
{
}
}
And displaying it in another class which extends Frame
JFrame newframe = new JFrame("Color Frame");
newframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GraphicUse gu = new GraphicUse();
newframe.add(gu);
newframe.setSize(250,300);
newframe.setVisible(true);
|
|
|
|
|