I need to add a captcha validator in a java swing application. I have been searching some libraries (JCaptcha and SimpleCatcha) but they are for web development.
Is there any library to use captcha on swing? and if it's not, is there a web page or repository with some captcha caracters to implement my own captcha?
I really appreciate your time and your help.
Thanks in advance.
JCaptcha can return a BufferedImage. From there it is not much difficult to get the image visible using a JLabel:
BufferedImage captcha = // Get the captcha
// See also com.octo.captcha.service.image.AbstractManageableImageCaptchaService.getImageChallengeForID(String)
JLabel label = new JLabel(new ImageIcon(captcha));
// ... add that label to a visible container of your Swing application
In version 1.0, you can use this: http://jcaptcha.sourceforge.net/apidocs/1.0/com/octo/captcha/service/image/AbstractManageableImageCaptchaService.html
In 2.0-alpha1, there is this: http://jcaptcha.sourceforge.net/apidocs/2.0-alpha1/com/octo/captcha/service/image/AbstractManageableImageCaptchaService.html#getImageChallengeForID(java.lang.String)
You can also check the overloaded version of those methods with an extra Locale argument.
In each case, there is a default implementing class DefaultManageableImageCaptchaService.
BufferedImage captcha = // Get the captcha
// See also
com.octo.captcha.service.image.AbstractManageableImageCaptchaService.getImageChallengeForID(String)
JLabel label = new JLabel(new ImageIcon(captcha));
// ... add that label to a visible container of your Swing application
Related
I created a winform form with a button and when I click on the button I´m invoking a Java AWT (.jar) process. After that I embed this process into a Panel using SetParent(...). The code:
var procStartInfo = new ProcessStartInfo();
procStartInfo.WindowStyle = ProcessWindowStyle.Normal;
procStartInfo.FileName = "file.jar";
var process = Process.Start(procStartInfo);
var container = new FormContainer();
container.Show();
Panel p = new Panel();
container.Controls.Add(p);
SetParent(process.MainWindowHandle, p.Handle);
The problem is when I embed the jar... the textboxes are not responding to any keypress event. I supose that the issue is related to the Java Swing application. Using any other moderm Java application every thing is working fine
Any idea if I need anything else to solve that problem
The problem is the bridge focus handler. In the java 1.8 version, the focus handler use multithread code and it seem that is it the problem in the java embeded application. We remove the async code and it works fine
i'm using Vaadin GridLayout in a project, and i want to make it big as the screen so i can arrange the UI of the app.
i'm a beginner in java, i tried .setWidth("100%"); , and also tried
to get the Screen resolution with Toolkit, but it did'nt help.
i've already searched around but none could've helping me.
can anyone give me a hint?
here is a part of it:
filter.setWidth("100%"); //TextField
entryList.setWidth("100%"); //Table
entryList.setHeight("100%");
blayout.addComponents(addNew,delete); //HorizontalLayout
blayout.setStyleName("buttons");
Styles style=Page.getCurrent().getStyles();
style.add(".buttons {float:right;}");
layout1.setMargin(true); //VerticalLayout
layout1.setSpacing(true);
layout1.addComponents(filter,entryList,blayout);
layout1.setWidth("100%");
layout1.setHeight("100%");
layout1.setSizeFull();
layout2.setSizeFull(); //VerticalLayout
layout2.addComponent(form); // form is a variable of an other class
layout2.setWidth("100%");
layout2.setHeight("100%");
MPanel panel1=new MPanel("Search");
MPanel panel2=new MPanel("Edit");
panel1.setSizeFull();
panel2.setSizeFull();
panel1.setContent(layout1);
panel2.setContent(layout2);
panel1.setWidth("100%");
panel1.setHeight("100%");
panel2.setWidth("100%");
panel2.setHeight("100%");
mlayout.setRows(1); //GridLayout
mlayout.setColumns(2);
mlayout.addComponent(panel1,0,0);
mlayout.addComponent(panel2,1,0);
mlayout.setSpacing(true);
addComponents(new MVerticalLayout(menue, mlayout)); //Creates Output
I know that JEditorPane does not render web elements well. Therefore I tried HtmlUnit. However, I wish to embed the JS supported browser into JEditorPane to see the results, and the .setPage() of JEditorPane does not take in a HTML page but a URL. Am on a Javax application. How may I fix this?
On a side note, I will need to embed visual data onto the browser later on, via D3. Appreciate all advice given.
Here is my code snippet:
webclient = new WebClient (BrowserVersion.CHROME);
currentpage = (HtmlPage) webclient.getPage("http://www.stackoverflow.com");
currentpage.executeJavaScript("document.write('Hello World!');");
jepuser = new JEditorPane();
jepuser.setEditable(false);
try{
jepuser.setPage(currentpage); //<---
jepuser.setContentType("text/html");
jepuser.updateUI();
}
catch(IOException e){
System.err.println(e);
}
spuser = new JScrollPane(jepuser);
spuser.setViewportBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
spuser.setSize(800, 420);
spuser.setLocation(280, 140);
spuser.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
//spuser.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
spuser.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
add(spuser, BorderLayout.CENTER);
JEditorPane can render some basic HTML (probably of version 3.2 or so)
HtmlUnit is a headless browser used mainly for unit testing
It seems that you want to embed a fully functional browser into your Java application. I would recomend trying JavaFX - it has a native browser control based on WebKit - WebView
I am new to Java User Interface ..
I have my main window with a TabbedPane ...
I want to use a library of graphics to display ... I have chosen this and i looked this example ...
ChartExample
but, how can I add the example chart on my TabbedPane?
The chart API you have chosen generates charts using Google's API. This means you'll have to display the image from the URL of chart.toURLString(); in your app. This could be as simple as putting a JLabel on your tabbed pane and setting its caption to <img src="(url)"/>, but I'm not entirely sure that handles HTTP downloads.
JLabel label = new JLabel("<img src='" + chart.toURLString() + "'/>");
tabbedPane.add(label);
If it doesn't, you can use javax.ImageIO.read(URL) to load the chart image into a BufferedImage and then create a new ImageIcon to put that onto the label:
URL url = new URL(chart.toURLString());
BufferedImage bimg = ImageIO.read(url);
Icon icon = new ImageIcon(bimg);
JLabel label = new JLabel(icon);
tabbedPane.add(label);
Your application will need a live Internet connection for the chart image to show up. If you need the images to work when you have no Internet access, you'll have to use a different charting library such as JFreeChart.
I am building a web application, in Java, where i want the whole screenshot of the webpage, if i give the URL of the webpage as input.
The basic idea i have is to capture the display buffer of the rendering component..I have no idea of how to do it..
plz help..
There's a little trick I used for this app:
count down demo app http://img580.imageshack.us/img580/742/capturadepantalla201004wd.png
Java application featuring blog.stackoverflow.com page ( click on image to see the demo video )
The problem is you need to have a machine devoted to this.
So, the trick is quite easy.
Create an application that takes as
argument the URL you want to fetch.
Then open it with Desktop.open( url
) that will trigger the current
webbrowser.
And finally take the screenshot with
java.awt.Robot and save it to diks.
Something like:
class WebScreenShot {
public static void main( String [] args ) {
Desktop.getDesktop().open( args[0] );
Robot robot = new Robot();
Image image = robot.createScreenCapture( getScreenResolutionSize() );
saveToDisk( image );
}
}
This solution is far from perfect, because it needs the whole OS, but if you can have a VM devoted to this app, you can craw the web and take screenshots of it quite easy.
The problem of having this app as a non-intrusive app is that up to this date, there is not a good html engine renderer for Java.
For a pure-java solution that can scale to support concurrent rendering, you could use a java HTML4/CSS2 browser, such as Cobra, that provides a Swing component for the GUI. When you instantiate this component, you can call it's paint(Graphics g) method to draw itself into an off-screen image
E.g.
Component c = ...; // the browser component
BufferedImage bi = new BufferedImage(c.getWidth(), c.getHeight(), TYPE_INT_RGB)
Graphics2d g = bi.createGraphics();
c.paint(g);
You can then use the java image API to save this as a JPG.
JPEGImageEncoder encoder = JPEGCodec.createEncoder(new FileOutputStream("screen.jpg"));
enncoder.encode(bi); // encode the buffered image
Java-based browsers typically pale in comparison with the established native browsers. However, as your goal is static images, and not an interactive browser, a java-based browser may be more than adequate in this regard.