Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how do you make a java applet?
#1
Hey all! I made a java code to solve stage 3 from gpq (the mastermind one), and I'd like to share it with the common mapler. Does anybody have any idea how to make it into a java applet or something?

I tested it a couple of times with my guild and now everyone thinks I'm a genious because I can solve it within seconds hehe Excellent (so it works). It's also made it a mastermind game while I was at it. (I wasn't allowed to play MS by my parents and got really, really bored).

Here's the code:

 code
And here is how it looks if you're wondering:

 pics
Reply
#2
quick googling provided these things:
http://java.sun.com/docs/books/tutorial/...nt/applet/
http://java.sun.com/docs/books/tutorial/...index.html

i still hate java, though. why not just code it in php?
Reply
#3
Links in ^ post if you really want to make it an applet, but the easiest way would probably be a form and javascript.
Reply
#4
Whoops ya I didn't really search for applets Tongue They seem a lot of work. Are there any other options?
The javascript form looks promising, I'll look a bit into that.

And I don't know php only java Tongue1
Reply
#5
I didn't look at your code extensively, but from the image you've provided of the GPQ solver, I'd have to say your methods could use refining. All it does is prevent you from trying combos that are known to be wrong, and it's not guaranteed to prevent failure. I'd suggest you go back to the drawing board and have the program make suggestions on what combos you should try next. You can do this by having the computer pre-compute probabilities and stuff for chance of success. It's sorta what people programming chess AIs do; they assign "points" to certain spots, and spots with the highest points are where the AIs are most likely to move.

In terms of actual GPQing, there's the "finish in 5 moves or less" method which it is recommended a computer should do, my method which I developed (that thread is hella old lmao, and I see that you've visited it), and the "try four of each item" method. Assuming perfect executiong of each method, the last one has a small chance of failure but probably gets you the fastest times out of all three, while the first one is infuriatingly hard to do with just people.
Reply
#6
Veneni Wrote:Whoops ya I didn't really search for applets Tongue They seem a lot of work. Are there any other options?
The javascript form looks promising, I'll look a bit into that.

And I don't know php only java Tongue1
Well javascript is kind of very similar to java syntax-wise... the functions you can use are sort of limited and i dont think you can import libraries, but the main difference is that you code it into the HTML. for example:
<script language="JavaScript" type="text/javascript">
function solve()
{
//get input from the text boxes using getElementById, output it either using alert() or through another text box.
}
</script>
<input type="submit" value="Solve" onclick="solve()">


also @kajiti, i have no idea how the stage works (in fact, i never did a GPQ), but considering the little options you have you can always just brute force it if nothing else succeeds.
Reply
#7
KajitiSouls Wrote:You can do this by having the computer pre-compute probabilities and stuff for chance of success. It's sorta what people programming chess AIs do; they assign "points" to certain spots, and spots with the highest points are where the AIs are most likely to move.

I guess by chance of success, you mean chance to solve with least number of moves.

I think the GPQ possibilities is small enough that it would be faster to just compute everything ahead of time, then just run through a sequence where you click the result (1 r 1 w, 2 r 1 w, etc) and it shows you what combination to do next to solve in minimal moves.



As for making it an applet, this is how my magic damage calculator had it.
Code:
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class MagicDamage extends Applet implements ActionListener {

  public MagicDamage() {
  }
  public static void main(String[] args) {
    MagicDamage tango = new MagicDamage();
    tango.init();
  }
swing and applet are pretty much necessary for the graphical part, awt is so it has a "click to calculate" button (or you can base it on modified fields I guess)

Code:
public void init() {
    // Construct
    blank = new JLabel(" ");
    Container contentTop1 = new Container();
    contentTop1.setLayout(new GridLayout(6,2));
Then there's the initialization which just builds a layout using swing components in a container.
Code:
calculate.addActionListener(this);
    add(contentTop, BorderLayout.NORTH);
    add(calculateButton, BorderLayout.CENTER);
    add(contentBottom, BorderLayout.SOUTH);

  }
At the end the 'calculate' button has an ActionListener so it'll be able to react to events, then they're added into the applet container itself.
Code:
public void actionPerformed(ActionEvent a) {
    try {
...
    } catch (Exception e) {
...
    }
  }
This runs when an action happens, and just calculates stuff. I think using a you can get information about what was clicked, if it's necessary.


Javascript is probably easier for this purpose, since HTML forms are a hell of a lot simpler to build. lol.
Reply
#8
I don't know pomegranate about javascript, but I'll try to make it into a cgi form and upload it somewhere if you want.
Reply
#9
First make a GUI to that application, then transforming it to an applet should be no problem.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)