How to create iframe JAVASCRIPT to JAVA in GWT? - java

Can anyone help me to javascript into java in gwt, and I need one simple example for this and I am gonna one JavaScript(URL) user form in to Java.
Thanking you

Try with Frame to create iframe in JAVA in GWT.
public class FrameExample implements EntryPoint {
public void onModuleLoad() {
// Make a new frame, and point it at Google.
Frame frame = new Frame("http://www.google.com/");
// Add it to the root panel.
RootPanel.get().add(frame);
}
}
Find more than 30 Code Examples here Java Code Examples for Frame

Related

I can't run a JFrame due to compiler errors & warnings

*I'm sorry for all of the trouble I may have caused you guys.
So, I am extremely new to programming with just a little experience in Java and Python. I was trying to make a program that would open a frame. In this frame there would be a button. When clicked, this button would play a song. I used a "recommended" code from YouTube. The code would begin to run, and then just stop. No frame would ever even appear. I showed it to a more experienced friend of mine. He said that the exact code ran just fine on his computer. I then sent him a screenshot of my project displayed on eclipse. He said that my JRE seemed to be missing some files. I tried a code that would just create a window, but it had the same problem. I am not sure what the JRE is, but I currently have JRE7. I don't know what I should do to fix this. Please help.
Error List
Severity and Description Path Resource Location Creation Time Id
The public type TopLevelWindow must be defined in its own file TGProject/src Frame.java line 4 1390698271752 73
The type TopLevelWindow is already defined TGProject/src TopLevelWindow.java Unknown 1390699351785 77
The method show(boolean) from the type Component is deprecated TGProject/src sound.java line 16 1390702839525 78
A link to the what my eclipse shows.
http://gyazo.com/3afdfa4f6750420f4e46deec40389340
A link to my Java file.
http://gyazo.com/257481d4ae9e2bb1d0ca93415a6c547e
Code for music
import java.awt.event.*;
import javax.swing.*;
import sun.audio.*;
import java.io.*;
public class sound {
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setSize(200,200);
JButton button = new JButton("Click me");
frame.add(button);
button.addActionListener(new AL());
//this is outdated, but should still work
frame.show(true);
}
public static class AL implements ActionListener{
public final void actionPerformed(ActionEvent e) {
music();
}}
public static void music()
{
AudioPlayer MGP = AudioPlayer.player;
AudioStream BGM;
AudioData MD;
ContinuousAudioDataStream loop = null;
try{
BGM = new AudioStream(new FileInputStream("Jambi.mp3"));
MD = BGM.getData();
loop = new ContinuousAudioDataStream(MD);
}catch(IOException error) {}
MGP.start(loop);
}
}
Code for Frame
import java.awt.*;
import javax.swing.*;
// Create a simple GUI window
public class TopLevelWindow {
private static void createWindow() {
//Create and set up the window.
JFrame frame = new JFrame("Simple GUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel textLabel = new JLabel("I'm a label in the window",SwingConstants.CENTER);
textLabel.setPreferredSize(new Dimension(300, 100));
frame.getContentPane().add(textLabel, BorderLayout.CENTER);
//Display the window.
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
createWindow();
}
}
Error 1
The public type TopLevelWindow must be defined in its own file
You either need to change.
public class TopLevelWindow {
To:
class TopLevelWindow {
Or do as reported and declare a new class for TopLevelWindow
Error 2
The type TopLevelWindow is already defined
I'm not sure what that means, but it might be solved by fixing the first problem.
Warning 3
The method show(boolean) from the type Component is deprecated
For any deprecation warning, go to the relevant method in the Java Docs. They should give details about what to use instead.
Tips
Compile often and ask as soon as you have a single error you do not understand.
Don't try to run code that shows problems in that window. Only experts should even try that.
You catch more flies with honey than with vinegar. Don't take the tone you did with Jayan, even if you think they are being harsh. People help for free, so have little time for questions that do not come up to standard. It might have been better to explain to the person that the question had now changed. Perhaps that would have made no difference to them, but either way, adding that kind of reply discourages everyone from helping.
"I used a "recommended" code from YouTube." Don't use YouTube videos to learn programming. They are often old, and in this case, they are using classes in the sun package for which there were better replacements since Java 1.3.
If you're really that new to programming, I would suggest to use an IDE (development environment) like for instance Netbeans or Eclipse and create a new JFrame form. You can then use the design view to graphically design your interface, IE drag your button on the screen. No need to go around programming frames. All you need to code is the implementation; what happens after you click the button.
After you posted the code, I had another look and this is what I've found:
Both classes have main methods. I ran both and each opened up a different window for me. Typically, you'll only want one main method. It's the main method! It's the starting point of your program and you can of course only have one starting point. At this time, your program is going to do two different things depending on what main method you run.
Still, this isn't your issue, because both mains are running for me. I think you must have the wrong version of java or something?
What I think you did is you pasted all that code into a file that wasn't called exacly "TopLevelWindow". If so, do that. I think your problem will go away.
Remember to only have one class per file, (barring inner classes; not something to concern yourself with as a beginner).

Show PDF file in GWT app

I have a PDF file stored in server and I want to display it on the client side. How can I make the pdf displayed in the required place?
You can create a frame widget with a reference to your PDF file. The Frame widget in GWT will render an HTML iFrame in your browser.
public class FrameExample implements EntryPoint {
public void onModuleLoad() {
// Make a new frame, and point it at Google.
Frame frame = new Frame("http://www.mydomain.com/path to my pdf");
// Add it to the root panel. or anywhere you want
RootPanel.get().add(frame);
}
}
I have used following. Its working fine. May be its usefull for you.
GWT Client side:
HTML pdf = new HTML("<embed src='http://www.mydomain.com/path to my pdf' width='100%' height='500px'></embed>");
PDFPannel.add(pdf);

Wicket modal window not displaying properly

I am trying to create a modal window for my application, but unfortunately I am unable to do so.
I have a page that extends WebPage and I have added a panel that extends Panel to it. The page and panel are written separately; that is, in panel.java and page.java. Now, I have added a modal window to the panel with the help of this Wicket Examples example (source). But when the page renders, I am seeing — by inspecting element of that page — that the div with wicket:id of "modal1" has attribute script="display: none". I don't know what to do. Any information will be very helpful to me.
One more thing: are
return new ModalContent1Page(ModalWindowPage.this.getPageReference(), modal1);
and
return new ModalContent1Page(ModalWindowPage.this, modal1);
the same?
Edit:
The problem is solved. Actually when I asked the question I did not have the code then. I was following the tutorial of RoseIndia, but I was unsuccessful and as I am using wicket 1.3.1 the PageReference class is not available there. So I solve it as:
final ModalWindow modalWindow;
add(modalWindow = new ModalWindow("modalVideo"));
modalWindow.setCookieName("modal-video");
modalWindow.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
modalWindow.setResizable(false);
modalWindow.setInitialHeight(215);
modalWindow.setInitialWidth(215);
modalWindow.setHeightUnit("px");
modalWindow.setPageCreator(new ModalWindow.PageCreator() {
public Page createPage() {
return new PlayVideo(ItemViewPanel.this.getPage(), modalWindow, itemId);
}
});
AjaxLink showModalLink;
add(showModalLink = new AjaxLink("showModal") {
#Override
public void onClick(AjaxRequestTarget target) {
modalWindow.show(target);
}
});
Thank you.
To answer your second question: no, those two lines of code are not the same. ModalWindowPage.this is the page itself, so its type is ModalWindowPage. getPageReference(), on the other hand, returns a PageReference, which is not in the same hierarchy.

export a JOGL applet and embedd into a html page

It is some time that I'm testing opengl with java and JOGL. I have a good result and I wan to publish it on the web, but I have a problem. I'm in eclipse, and I'm testing an Applet with JOGL.
EDIT: Thanks to Ricket answer it fixed this problem
first of all i have this run time error (but the program works correctly):
java.lang.IllegalArgumentException:
adding a window to a container at
EDIT: but it still doesn't work:
then I found this incredibly clear page
and I did what is said. I open html with the browser, the libs are downloaded, but it stops at Starting applet AppletHelloWorld, as that is the name I gave to my applet.
Maybe I am missing something like a main function or exporting the jar properly?
This is my main code:
public class AppletHelloWorld extends Applet
{
public static void main(String[] args)
{
JFrame fr=new JFrame();
fr.setBounds(0,0,1015,600);
fr.add(new AppletHelloWorld());
fr.setVisible(true);
}
public void init()
{
setLayout(null);
MyJOGLProject canvas = new MyJOGLProject(); //MyJOGLProject extends JFrame
canvas.run(); // this do setVisible(true)
} //....
Just as the error says, you're trying to add a window to a container. A JFrame is a window. You can't add a JFrame to anything, including a Container. I think perhaps you either don't know what a JFrame is, or don't know what a Container is.
Ideally you would have MyJOGLProject extend GLEventListener instead. Then your init function would make a new GLCanvas, add an instance of MyJOGLProject to it (via addGLEventListener), and then add the GLCanvas to your applet.
Alternatively, if you're okay with the applet popping up a JFrame, then simplify your init method:
public void init() {
setLayout(null);
MyJOGLProject canvas = new MyJOGLProject();
canvas.setVisible(true);
}
That should do it.
Use JApplet. I think that's the reason why it fails.
(Use Webstart with JNLP in NetBeans)

Why my Swing based GUI application is not responding?

I am trying to create my first GUI application using (Java + Eclipse + Swing). This is my code:
import java.awt.*;
import javax.swing.*;
public class HelloWorldSwing extends JFrame {
JTextArea m_resultArea = new JTextArea(6, 30);
//====================================================== constructor
public HelloWorldSwing() {
//... Set initial text, scrolling, and border.
m_resultArea.setText("Enter more text to see scrollbars");
JScrollPane scrollingArea = new JScrollPane(m_resultArea);
scrollingArea.setBorder(BorderFactory.createEmptyBorder(10,5,10,5));
// Get the content pane, set layout, add to center
Container content = this.getContentPane();
content.setLayout(new BorderLayout());
content.add(scrollingArea, BorderLayout.CENTER);
this.pack();
}
//============================================================= main
public static void main(String[] args) {
JFrame win = new HelloWorldSwing();
win.setTitle("TextAreaDemo");
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setVisible(true);
}
}
The code was taken from here.
When I run the application from Eclipse the expected window appears (So, it's good. I see what I want to see). However, when I try to close the window or try to write something in the text area the program freezes. The OS writes me that program is not responding (I try it on Ubuntu).
Can anybody help me to find the reason of the problem?
Thank you in advance for any help.
I'm sure this doesn't have to do with the code, as others have found the code runs just fine on their machines - which points to a machine specific issue. From within Eclipse, make sure it is setup to use the expected JDK/JRE. However, before worrying about how Eclipse is handling your situation, I'd run things by hand first - especially since you've got a very simple class.
I would check to ensure that you're using the expected compiler and runtime. On Linux:
which javac
which java
If they're both what you expect, do the following:
javac HelloWorldSwing.java
java HelloWorldSwing
If you get a similar problem, then you know it's not the Eclipse configuration and it's something else. If you're not using the latest JDK, upgrade to the latest. If you're already at the latest, it could be a display driver. Do other JAVA swing programs work on this computer? I'm sure you could find some on the net, download an app already packaged as a jar and try running it.
did you try using the eventdispatcherthread to view the JFrame?
something like:
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
createAndViewJFrame();
}
});
}
public void createAndViewJFrame(){
JFrame win = new HelloWorldSwing();
win.setTitle("TextAreaDemo");
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setVisible(true);
}
then your frame would be shown by the swing dispatcher thread.
hope it helped, although im just guessing...
Update: as commenters pointed you i f**ed up the invokeLater() call. I just edited this post to correct that. Thanx go to yishai & willcodejavaforfood for pointing it out!
frank
You need to catch the exit event and
respond with a System.exit( 0 );
You should be able to find that in
most swing examples online.
wrong stuff... sorry... coffee... argh....

Categories