Firstly I am no longer a student and doing this for other purposes, so don't hold back on the help ;)
I want to incorporate a simple program into my webpage. I want 4 buttons labelled right arm, left arm, activate voice and walk forward. There will be a box above these buttons showing an image of a robot and as the buttons are pressed by the user I want a different image to be loaded in the box.
So if the right arm button is pressed the image with the robot raising its right arm will need to be displayed.
So basically all I want the buttons to do is to load the image that belongs to each one. I am assuming java is the best choice? I have the open source Java package, would I need any other software when it comes to embedding it into a webpage? My webpage is done on dreamweaver and I am pretty good with html. Would appreciate it if someone could point me to the right direction.....Thanks
Don't use Java for this. Use JavaScript. Something like this:
HTML:
<img src="one.jpg" id="firstImage" />
<img src="two.jpg" id="secondImage" />
<button id="doSomething">Do Something</button>
<button id="doSomethingElse">Do Something Else</button>
CSS:
img {
display: none;
}
JavaScript:
var hideImages = function() {
$('#firstImage').hide();
$('#secondImage').hide();
};
$('#doSomething').click(function() {
hideImages();
$('#firstImage').show();
});
$('#doSomething').click(function() {
hideImages();
$('#secondImage').show();
});
What this essentially does is initially display no images, just buttons. Then as each button is clicked, the corresponding image is displayed. (And all other images are first hidden, since previous button clicks would have displayed previous images.)
This is an overly simple proof of concept, of course. At the very least you'll want to use better variable names :) This just demonstrates the idea of how you'd show/hide images in JavaScript in response to button clicks. (This also assumes the use of jQuery, which is a safe assumption these days. The easiest way to use that is to refer to a CDN link in your page, using a standard HTML script tag.) You can see this code in action here (though the images are broken, of course.)
If there are a lot of buttons and a lot of images, you may be able to re-factor the code to be less repetitive as well. Maybe store the images in an array and have a single button click handler which can associate the sending button with the correct array element, etc. That's up to you.
There are many technologies that could help you: javascript is one of them and it would be much simpler than using Java for such simple thing. You can use Java applet if you really want to use Java for that project.
Related
I have been put in charge of a site for one of our clients that was built by an outside company. One of the additional requests is that she wants to be able to position an image on their news page either on the left, right or centred.
There is an administration system in place where the client can create a news article and add an image however I need to know if there is anyway I can change the image position on the 'news items' page depending on whether the left, right or centred radio button has been checked on the administration panels 'add a news item' page.
I think it is possible with Java but it's not something I have had to do before and am looking for a nudge in the right direction really.
I think it is possible with Java but the tutorials I have found show me how to change the css with Java on the current page but not on a different page.
Any advice would be much appreciated
Write 2 css classes, class1: for left alignment and class2: for right alignment. Suppose if there are 2 radio buttons. On click of each radio you can toggle value of class.
$("#radioId1").click(function () {
$('#para1').removeClass('class1');
$('#para1').addClass('class2');
});
$("#radioId2").click(function () {
$('#para1').removeClass('class2');
$('#para1').addClass('class1');
});
I am working on a research project.The scenario is this.
I am taking the screenshot of my desktop and then I process it using an API to get the position of a certain text on my Desktop.e.g , say I have the browser open on my desktop and I am on stackoverflow.Now I want to search the position of the logo stackoverflow on the screenshot taken.Then I want to simulate a click on it.I am using Java platform.
Now I have 2 questions:
1)Is there any free API(OCR) which I can use to process the screenshot to fetch text position (or can be done by some trick) and gives good results.
Or Any way you can suggest that I can use (instead of taking screenshot and processing it) to get the position of any text on the screen.
2)How can I simulate the click on the screen using the code by a background program running(I mean I have done it in Swing and other language UIs but this time its different as Now I want to click on the screen.
If I understood you right you want to move your mouse and click on the screen. That not that hard you could use the robot class from Java!
For example:
Robot rob = new Robot();
rob.keyPress( KeyEvent.VK_ENTER );
or what ever, there are so much bottons and movements you could with it. A list of all methods you find here.
And your other question I can't answer. I think there is no API that is able to search a text and give you the position. But what I know is that the robot class is able to capture the screen and put it into a BufferedImage. With it you could compare two pictures.
Maybe you could get use of this but I don't know if it is what you search.
I was asked to write a JDialog separated into left and right panel. The left panel shows a demo HTML template gallery (small sized), and right panel shows series or list of images. I want to make it such that I can drag image on the list and place it on the gallery (or maybe drag out some image from the gallery). The problem is I don't know where to start with this, can anybody give me some idea?
An HTML gallery typically uses JS to do the 'heavy lifting' (I'm guessing it will require a slideshow as well). While Swing components support HTML (to an extent) they do not support JS.
I recommend not trying to render the HTML/JS in the GUI, instead, provide a JList in the GUI of the image+name objects chosen by the user (using JFileChooser). When each image is selected, you can show the 'preferred name' in a JTextField that allows the user to edit it.
Image order can be shown by the order in the list. To change the order, implement Drag'n'Drop. See the Drag and Drop and Data Transfer lesson for more details.
You will probably need a JLabel in the CENTER of the GUI to display the (full size) selected image, and show the order & timing of the slideshow.
Once the user is happy with the image selections, the order, the names & timing. Offer them a button to write all the details to a single directory including the HTML, script & images (easier). Once the HTML is written, invoke Desktop.open(File) to display the finished product to the user.
As to how you do all that, it is really beyond the scope of an answer on SO. You would need to do the tutorial on each part, and come back with more specific questions.
Total noob here.
I am in the process of building my hobby website and feel that I could, with some hard work, create a fully functional site. However, I am rather stuck on modal popout window.
I understand the basics of getting one to work, i.e. download jquery or related java library, attach said library to webpage in the section. Apply modal popout in similar way making sure to include the CSS for it.
I can get it to function in my site, so with Shadowbox I managed to get it to actually popout. Where I am stuck, with Shadowbox in particular, is actually putting stuff inside the modal popout. I am really only interesting putting text in the modal popout with maybe a link or small picture to compliment the text.
What is hindering me is my lack of knowledge. This may be either a lack of understanding with regards to class attributes or href attributes, or a lack of knowledge. The only progression I have made with this is simply because of the copy and paste, and some image path manipulation with Shadowbox. I am still horribly confused as to how the script activates, what tags/attributes I need to make to ensure data within a is included in the modal popout window.
I would really like to have a modal popout like this http://typedeskref.com/ but feel that this is far, far beyond me.
In summary: I don't know how to put text/images inside of a modal popout. I don't know how a modal popout is activated and how to ensure I can control what is kept inside of it. The reason why I say this is because the limited sucess I have had with Shadow box is because it has somehow managed to pick up everything that is on my site, images, links etc. So when the modal popout is opened, there is my site, in modal form.
Thanks for taking the time to read this. I really appreciate any help or advice you can give me. Even a shove in the direction where such information can be located would be great!
p.s. I am using dreamweaver cs5
Depends on how crazy and amazing you want your dialogs to be. It could be something as simple as downloading jQuery UI Dialogs (http://jqueryui.com/demos/dialog/) and then doing this.
<div id="dialog">Hello</div>
<a id="button1">One</a>
<a id="button2">Two</a>
// Do the setup when the page has loaded
$(function() {
// Create the dialog, don't show it on page load
$("#dialog").dialog({autoOpen:false});
// Button One will show the dialog
$("#button1").click(function() { $("#dialog").dialog("open"); });
// Button Two changes the content, THEN shows the dialog.
$("#button2").click(function() {
$("#dialog").html("Goodbye");
$("#dialog").dialog("open");
});
});
It's a starting point. Same dialog, changing the content, triggered by clicking a link. That library has all manner of options (animations, etc) and you can style it to whatever look-and-feel you like.
Here is a demo: http://jsfiddle.net/dYMvH/
I will explain my question clearly.
I need to zoom in/zoom out the world map.
When I click on the particular country in map, control should redirected to new page with respective the country.
I dont have any idea about this in java. Please explain the steps to acheive the above task.
As the question is quite general, here is a general answer: Zooming often means, that you want to display a certain percentage of somethin, and not the whole, where your size of the displayed will not change.
But in your case it seems more like a "find a mouse click in a polygon" thing. So you have to add a selection/click listener to whatever widgets you use (Swt? swing? ....?) where you change what your program renders.
It sounds like you may be trying to reinvent the wheel. Google etc have already solved this problem rather well. It might be better to incorporate an existing solution into your application. Have a look at GoogleEarth inside Java Swing.