|
Thanks, that was idd my problem. That's why I wanted to know if there was something similar in .Net. Then I could map my .Net knowledge with this feature.
The articles are indeed lengthy and vague imho.
V.
|
|
|
|
|
The interview went unexpectedly well .
They figured that with my experience I could learn the new technologies very quickly anyway and they seemed more interested in motivation.
V.
|
|
|
|
|
what is the advance java and functon...??????
|
|
|
|
|
What indeed? Please think about your question before posting, as the above makes no sense. In fact you could probably type it into Google and get a reasonable answer.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
i have created one java servlet code from which i get 3 field from database table and i want to show this field on my js(java script) page in html tag like <lable>Name= and i want to show first name field from datbase infront of lable Name..
|
|
|
|
|
OK, now we know what you want. What's your question?
|
|
|
|
|
i have created a one java script file in that i have written a html code in boilerplate variable and ajax to call servlet .
in java servlet i have written a code for select query as to select data from database table and store tihs value in resultset
i want to store this resultset value in to javascript variable.
how i store it ???????
eg:-suppose i have table with firstname and Lastname fields and if i retrive this column in java servlet then i want this two column value to save/store in a java script variable on java script file
like var fname=????
var lname=????
|
|
|
|
|
Hi, i want to implement a voice chat in java . can anyone tell how to read abd send the voice data???
|
|
|
|
|
|
I'm working on a system and we have a problem on printing. System send an html content to the print class and we could not get a proper print page. I'm writing my codes. Please have a look..(sorry about my bad english)
PrintableEditorPane pane = new PrintableEditorPane(
html.getText());
pane.setContentType("text/html");
EditorPanePrinter pnl = new EditorPanePrinter(pane, new Paper(), new Insets(18, 18, 18, 18));
pnl.print();
---and this is my printing class
package org.esse.utility.image;
import javax.swing.*;
import javax.swing.text.View;
import javax.swing.text.Position;
import javax.print.PrintService;
import java.awt.print.*;
import java.awt.*;
import java.awt.geom.Area;
import java.awt.geom.AffineTransform;
import java.util.ArrayList;
public class EditorPanePrinter extends JPanel implements Pageable, Printable {
JEditorPane sourcePane;
Paper paper;
Insets margins;
ArrayList<pagepanel> pages;
int pageWidth;
int pageHeight;
View rootView;
public static int PAGE_SHIFT = 20;
PageFormat pageFormat;
public EditorPanePrinter(JEditorPane pane, Paper paper, Insets margins) {
initData(pane, paper, margins);
}
public void initData(JEditorPane pane, Paper paper, Insets margins) {
JEditorPane tmpPane = new JEditorPane();
tmpPane.setEditorKit(pane.getEditorKit());
tmpPane.setContentType(pane.getContentType());
tmpPane.setText(pane.getText());
this.sourcePane = tmpPane;
this.paper = paper;
this.margins = margins;
this.pageWidth = (int) paper.getWidth();
this.pageHeight = (int) paper.getHeight();
pageFormat = new PageFormat();
paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight() );
pageFormat.setPaper(paper);
doPagesLayout();
}
public void doPagesLayout() {
setLayout(null);
removeAll();
this.rootView = sourcePane.getUI().getRootView(sourcePane);
sourcePane.setSize(pageWidth - margins.top - margins.bottom, Integer.MAX_VALUE);
Dimension d = sourcePane.getPreferredSize();
sourcePane.setSize(pageWidth - margins.top - margins.bottom, d.height);
calculatePageInfo(); int count = pages.size();
this.setPreferredSize(new Dimension(pageWidth * 2 + 50, PAGE_SHIFT + count * (pageHeight + PAGE_SHIFT)));
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
AffineTransform old = ((Graphics2D) g).getTransform();
((Graphics2D) g).setTransform(old);
}
protected void calculatePageInfo() {
pages = new ArrayList<pagepanel>();
int startY = 0;
int endPageY = getEndPageY(startY);
while (startY+pageHeight-margins.top-margins.bottom <
sourcePane.getHeight() * ( pageWidth /
sourcePane.getPreferredSize().getWidth()) / 1.8) {
Shape pageShape = getPageShape(startY, pageWidth - margins.left - margins.right, pageHeight - margins.top - margins.bottom, sourcePane);
pages.add(new PagePanel(startY, endPageY, pageShape));
startY = endPageY;
endPageY = getEndPageY(startY);
}
Shape pageShape = getPageShape(startY, pageWidth - margins.left - margins.right, pageHeight - margins.top - margins.bottom, sourcePane);
pages.add(new PagePanel(startY, endPageY, pageShape));
int count = 0;
for (PagePanel pi : pages) {
add(pi);
pi.setLocation(PAGE_SHIFT, PAGE_SHIFT + count * (pageHeight + PAGE_SHIFT));
count++;
}
}
protected int getEndPageY(int startY) {
int desiredY = startY + pageHeight - margins.top - margins.bottom;
int realY = desiredY;
for (int x = 1; x < pageWidth; x++) {
View v = getLeafViewAtPoint(new Point(x, realY), rootView);
if (v != null) {
Rectangle alloc = PrintApp.getAllocation(v, sourcePane).getBounds();
if (alloc.height > pageHeight - margins.top - margins.bottom) {
continue;
}
if (alloc.y + alloc.height > desiredY) {
realY = Math.min(realY, alloc.y);
}
}
}
return realY;
}
protected View getLeafViewAtPoint(Point p, View root) {
return getLeafViewAtPoint(p, root, sourcePane);
}
public static View getLeafViewAtPoint(Point p, View root, JEditorPane sourcePane) {
int pos = sourcePane.viewToModel(p);
View v = sourcePane.getUI().getRootView(sourcePane);
while (v.getViewCount() > 0) {
int i = v.getViewIndex(pos, Position.Bias.Forward);
v = v.getView(i);
}
Shape alloc = PrintApp.getAllocation(root, sourcePane);
if (alloc.contains(p)) {
return v;
}
return null;
}
public static Shape getPageShape(int pageStartY, int pageWidth, int pageHeight, JEditorPane sourcePane) {
Area result = new Area(new Rectangle(0, 0, pageWidth, pageHeight));
View rootView = sourcePane.getUI().getRootView(sourcePane);
Rectangle last = new Rectangle();
for (int x = 1; x < pageWidth; x++) {
View v = getLeafViewAtPoint(new Point(x, pageStartY), rootView, sourcePane);
if (v != null) {
Rectangle alloc = PrintApp.getAllocation(v, sourcePane).getBounds();
if (alloc.y < pageStartY && alloc.y + alloc.height > pageStartY) {
if (!alloc.equals(last)) {
Rectangle r = new Rectangle(alloc);
r.y -= pageStartY;
result.subtract(new Area(r));
}
}
last = alloc;
}
}
last = new Rectangle();
for (int x = 1; x < pageWidth; x++) {
View v = getLeafViewAtPoint(new Point(x, pageStartY + pageHeight), rootView, sourcePane);
if (v != null) {
Rectangle alloc = PrintApp.getAllocation(v, sourcePane).getBounds();
if (alloc.y < pageStartY + pageHeight && alloc.y + alloc.height > pageStartY + pageHeight) {
if (!alloc.equals(last)) {
Rectangle r = new Rectangle(alloc);
r.y -= pageStartY;
result.subtract(new Area(r));
}
}
last = alloc;
}
}
return result;
}
//pageable methods
public int getNumberOfPages() {
return pages.size();
}
public PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException {
return pageFormat;
}
public Printable getPrintable(int pageIndex) throws IndexOutOfBoundsException {
return this;
}
public int print(Graphics g, PageFormat pageFormat, int pageIndex)
throws PrinterException {
if (pageIndex < pages.size()) {
pageFormat.getPaper().setImageableArea(0, 0, paper.getWidth(), paper.getHeight());
pages.get(pageIndex).isPrinting = true;
pages.get(pageIndex).paint(g);
pages.get(pageIndex).paintAll(g);
pages.get(pageIndex).isPrinting = false;
return PAGE_EXISTS;
}
return NO_SUCH_PAGE;
}
class PagePanel extends JPanel {
int pageStartY;
int pageEndY;
Shape pageShape;
boolean isPrinting = false;
JPanel innerPage = new JPanel() {
public void paintComponent(Graphics g) {
super.paintComponent(g);
AffineTransform old = ((Graphics2D) g).getTransform();
//double scales = pageWidth
/ sourcePane.getPreferredSize().getWidth();
//scales = scales / 1.8;
Shape oldClip = g.getClip();
Area newClip = new Area(oldClip);
if (isPrinting) {
newClip = new Area(pageShape);
} else {
newClip.intersect(new Area(pageShape));
}
g.setClip(newClip);
g.translate(0, -pageStartY);
//((Graphics2D) g).scale(scales, scales);
sourcePane.paint(g);
for (Component c : sourcePane.getComponents()) {
AffineTransform tmp = ((Graphics2D) g).getTransform();
g.translate(c.getX(), c.getY());
((Container) c).getComponent(0).paint(g);
((Graphics2D) g).setTransform(tmp);
}
((Graphics2D) g).setTransform(old);
g.setClip(oldClip);
}
};
public PagePanel() {
this(0, 0, null);
}
public PagePanel(int pageStartY, int pageEndY, Shape pageShape) {
this.pageStartY = pageStartY;
this.pageEndY = pageEndY;
this.pageShape = pageShape;
setSize(pageWidth, pageHeight);
setBackground(Color.white);
setLayout(null);
add(innerPage);
innerPage.setBounds(margins.left, margins.top, pageWidth - margins.left - margins.right, pageHeight - margins.top - margins.bottom);
}
// public void paintComponent(Graphics g) {
// super.paintComponent(g);
// g.setColor(Color.black);
// g.drawRect(0, 0, getWidth() - 2, getHeight() - 2);
// }
}
public void print() {
print((PrintService) null);
}
public void print(PrintService ps) {
try {
PrinterJob pj = PrinterJob.getPrinterJob();
JFrame tmp = null;
if (this.getParent() == null) {
tmp = new JFrame();
tmp.getContentPane().add(new JScrollPane(this));
tmp.pack();
tmp.setVisible(false);
}
pj.setPageable(this);
if (ps != null) {
pj.setPrintService(ps);
}
// sending the document to the printer page
Boolean appliedPrint = pj.printDialog();
if(appliedPrint)
pj.print();
if (tmp != null) {
tmp.dispose();
}
} catch (PrinterException e1) {
e1.printStackTrace();
}
}
}
|
|
|
|
|
Waaaaaaaaay too much code. The least you could do is format it as a <code> block.
|
|
|
|
|
the (inputString == reverseString) if-conditional always returns false (even if it is true. please help. Couldn't figure this out. thanks.
import java.util.Scanner;
public class ReverseString{
public static void main (String[] args){
String inputString="";
int inputStringLength;
String reverseString="";
String stringHolder="";
Scanner in = new Scanner(System.in);
System.out.print("Enter a String: ");
inputString = in.next();
inputStringLength = inputString.length();
System.out.println("Input String is : " +inputString);
for (int i = 0; i<inputStringLength; i++){
stringHolder = inputString.charAt(i) + stringHolder;
reverseString = stringHolder;
}
System.out.println(reverseString);
System.out.println("inputString = " + inputString);
System.out.println("input length =" + inputString.length() + "reverse length " +reverseString.length());
System.out.println("Now let's test to see if your input is a palindrome (like hannah or 'a man, a plan, a canal, panama') \n" + "Does "+ inputString +" = the same forward and reversed? \n^^^ \n^^^ " );
if (inputString == reverseString){
System.out.println("yes!");
System.out.println(" YES!! Eureka! " + inputString + " == " + reverseString + "! Thus, " + inputString + " is a palindrome! gratzee!");
}else {
System.out.println("no");
System.out.println("NO!! \n" + inputString + " != (does not equal) " + reverseString + "\n So " + inputString + "is not a palindrome! Oh well no prob!" );
}
}
}
I've tried using scaffolding code to test for what is going on. I think someway reverseString is created may be a problem. But when I print reverseString and inputString they both have the same string length and visibly the same characters...so I don't know what the solution is at present.
|
|
|
|
|
You should be using String.equals() [^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hey really? Thanks Richard MacCutchan! Thanks for taking the time to look at that code, too. It's not yet solved b/c I have to try that comparison method, but thanks!!
However, I thought it was something like that so made a mini test program.
String var1 = "hello";
String var2 = "hello";
if (var1==var2){
System.out.println("equal!");
}
and THAT did show they were equal. If the String.equals() method works (and gets my ReverseString.java program to work, why would that above var1==var2 work but not so with inputString and reverseString?
Thanks!!
|
|
|
|
|
Well if you had read a bit more detail from the page I pointed you to you would understand that the above expression works only because var1 and var2 refer to the same String object, not because the strings themselves match. And from that it follows that you must always use String.equals() to get an actual comparison of the characters within the strings.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
oh bloody hell. was so excited to see a response, didn't even notice that you linked something.
I researched and found
"The == operator will only be true if two String references point to the same underlying String object. Hence two Strings representing the same content will be equal when tested by the equals(Object) method, but will only by equal when tested with the == operator if they are actually the same object."
which I "sorta" understand. like same object in memory referenced and two diff objects but with same string value (== only works as true with the former)
so == seems to compare objects in memory and String.equals() actually compares Strings (content of String objects).
Sweet am finally getting this a bit!!
Thanks for such complete answer...and now that that obstacle is resolved, my coding can progress for the day!
(Also I tried it and now that mini-app totally works. Thanks again!)
This is site is so much better than stackoverflow haha.
|
|
|
|
|
johtnkucz wrote: This is site is so much better than stackoverflow haha.
If nothing else you get a 5 for that comment.
Seriously, thanks for the feedback, it's always welcome, and good luck with your project(s).
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I never rely on luck. I prefer efficiency and preparation (and utilizing awesome resources like this site!)!! Seriously thanks for the positive feedback...on my positive feedback!!
Seriously though This is my number one code-help (I have other resources for tutorials and stuff but if get stuck and need help) this owns other sites, including stack overflow. Your response was extremely helpful. thanks again so much for looking at code.
And re stackoverflow. I hate that site. Most comments and posts have this gross disgusting milieu of (ooh look how much coding I know or some cheesy leet rubbish of "no, you're supposed to post this way..or that way.." or whatever.
I just was thoroughly stumped, chucked up some code:
1. got the EXACT answer that was the prob
2. learned somethign I never fully understood even after a wretched computer science class and most all autodidactic(== compares objects not content of objects and strings may be equal but diff objects, so if linked to diff objects same content will appear as not equal because their objects are not equal but their content is) .
That's the epitome of helpful. Anyways if one gets similar exchanges, this is num 1 code resource. good times. The layout of forum posts/responses is unique and novel but appealing, too. Good tiems.
Were you involved in making this site or something, or just prefer this (anti overflow) to other sites, too. Cheers. thanks.
|
|
|
|
|
johtnkucz wrote: Were you involved in making this site or something
No, I'm just one of the 8.5 million ...
If you want to know a bit more about the site see here[^], and if you want to know who are the great people who did make the site then look here[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Buy using stringBuffer and string equals method we can check try this following code
import java.util.Scanner;
import java.lang.*;
public class ReverseString{
public static void main (String[] args){
String inputString="";
int inputStringLength;
String reverseString="";
String stringHolder="";
Scanner in = new Scanner(System.in);
System.out.print("Enter a String: ");
inputString = in.next();
StringBuffer sb=new StringBuffer(inputString);
sb=sb.reverse();
if(inputString.equals(sb.toString()))
{
System.out.println("palindrome");
}
else
{
System.out.println("Not palindrome");
}
}
}
|
|
|
|
|
I have created a java servlet in which i have fetch the value from database using mysql i just want to use this fetch value in to my Js file.
So how can i do this????
Reply
swapnil
|
|
|
|
|
|
I display the progress bar for downloading attachments and it works fine … but when I am downloading some attachments I get the exception message:
Exception in thread "main" com.sun.mail.util.DecodingException: BASE64Decoder: Error in encoded stream: needed 4 valid base64 characters but only got 1 before EOF, the 10 most recent characters were: "Q3w5ilxj2P"
I found the explanation:
Certain IMAP servers do not implement the IMAP Partial FETCH functionality properly. This problem typically manifests as corrupt email attachments when downloading large messages from the IMAP server. To workaround this server bug, set the "mail.imap.partialfetch" property to false. You'll have to set this property in the Properties object that you provide to your Session.
http://java.sun.com/products/javamail/NOTES113.txt
So I turned off partial fetch:
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
props.setProperty("mail.imaps.partialfetch", "false");
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", "<username>","<password>");
this solved the problem ….however the method getInputStream() from the Part class blocks the thread until the attachment is completely downloaded and it is impossible to get the information about the number of bytes which have been already downloaded from mailbox. Without this information it is impossible to display the progress bar. So is there a way to obtain this information and display the progress bar?
|
|
|
|
|
Firstly, put the download on a separate thread so that you don't hang.
Secondly, can you get the size of the attachment?
You can always use a guestimate of how long is left, and then tick your progress accordingly.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|