Author Topic: Random simple java programs that actually do something useful.  (Read 34961 times)

0 Members and 1 Guest are viewing this topic.

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Random simple java programs that actually do something useful.
« Reply #45 on: December 13, 2010, 08:32:09 pm »
now how do I display text on JPanel?
Sig wipe!

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Random simple java programs that actually do something useful.
« Reply #46 on: December 13, 2010, 08:34:24 pm »
Do you know what the API is? in general, they'll give methods for you to do most anything you can do in java. i'm not explaining how and just giving you a link to be rude, it's so that everytime you want to do something new in java, you can look at the API to see if there's a method that does what you want.


Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Random simple java programs that actually do something useful.
« Reply #47 on: December 13, 2010, 08:37:46 pm »
thank you for the link.
I won't bother you no more.... :D
Spoiler For Spoiler:
bother bother  >:D
Sig wipe!

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Random simple java programs that actually do something useful.
« Reply #48 on: December 13, 2010, 08:38:51 pm »
lol you aren't bothering me! if you can't find something in the API i'd be glad to help. like if you want to display an image, and then after that you want to rotate it. and after that you want to make a racing game that scrolls. i can help you along there  :)


Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Random simple java programs that actually do something useful.
« Reply #49 on: December 15, 2010, 10:00:28 pm »
"encoding" and "decoding" a string. you really aren't... for example, does this look recognizable?
Code: [Select]
{0171,0157,0165,040,0150,0141,0166,0145,040,0154,0157,0163,0164,040,0164,0150,0145,040,0147,0141,0155,0145,056}

i bet this does though:
Code: (translation) [Select]
you have lost the game.

to encode:

Code: [Select]

import java.util.*;

public class Array{

public static void main(String[] args){
Scanner reader = new Scanner(System.in);
String str = reader.nextLine();
String obfuscation = "{";
for(int i = 0; i < str.length(); i++){
obfuscation += "0" + Integer.toOctalString((int)str.charAt(i));
if(i + 1 != str.length())
obfuscation += ",";
}
obfuscation += "}";
System.out.println("encoded: " + obfuscation);
}

}

to decode:
Code: [Select]
public class Array2{

public static void main(String[] args){
int[] ints = <output from first program>;
for(int i: ints)
System.out.print((char)i);
}

}

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Random simple java programs that actually do something useful.
« Reply #50 on: December 16, 2010, 04:54:51 am »
Damnit I lost D:<

Nice code, though.

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Random simple java programs that actually do something useful.
« Reply #51 on: December 18, 2010, 09:01:41 pm »
insult generator! they're actually pretty lame.. i tried.

Code: [Select]
import java.util.*;

public class Insult{
static Random r = new Random();
public static void main(String[] args){
System.out.println(randomStart() + randomAdj() + randomNoun() + "you " + randomPersonAdj() + randomInsult() + ". " + randomEnd());
Scanner reader = new Scanner(System.in);
System.out.println("Want another opinion? (y/n)");
if(reader.nextLine().equalsIgnoreCase("y"))
main(null);
}

public static String randomStart(){
String[] starts = {"What is this ","Why would you leave this ",};
return starts[r.nextInt(2)];
}
public static String randomAdj(){
String[] adj = {"stupid ","blatant ","moronic ","abominable "};
return adj[r.nextInt(4)];
}
public static String randomNoun(){
String[] noun = {"piece of garbage ","filth ","waste "};
return noun[r.nextInt(3)];
}
public static String randomPersonAdj(){
String[] adj = {"deficient ","senseless ","rash ","puerile ","nonsensical ","thick headed ","fat ","pointless ","obtuse "};
return adj[r.nextInt(9)];
}
public static String randomInsult(){
String[] insults = {"crud of the gene pool","failure","waste of breath","imbecile","incompetent monkey"};
return insults[r.nextInt(5)];
}
public static String randomEnd(){
String[] ends = {"Get lost.","Go climb a mountain.","Why don't you leave?","Just stop. Stop it now.","Seriously? Vamoose.","The Game."};
return ends[r.nextInt(6)];
}
}

for example:
Why would you leave this blatant piece of garbage you thick headed failure. Go climb a mountain.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Random simple java programs that actually do something useful.
« Reply #52 on: December 18, 2010, 09:41:13 pm »
Lol XD

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Random simple java programs that actually do something useful.
« Reply #53 on: December 19, 2010, 03:43:20 pm »
Someone was mentioning JFrame programs, right?

Code: [Select]
import javax.swing.*;

public class HelloWorldSwing
{
public static void main(String args[])
{
JFrame frame = new JFrame("Hello");
JLabel label = new JLabel("Hello, Swing World");
frame.getContentPane().add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}

I coded a bit of JFrame yesterday, I'll post a JFrame numbar generator later :)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Random simple java programs that actually do something useful.
« Reply #54 on: December 19, 2010, 03:51:10 pm »
What's JFrame? Is it a derivative of java or is it a library, like JQuery for JS?

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Random simple java programs that actually do something useful.
« Reply #55 on: December 19, 2010, 03:53:57 pm »
What's JFrame? Is it a derivative of java or is it a library, like JQuery for JS?

It's like wxPython for python :) Or Tkinter for Python :)
« Last Edit: December 19, 2010, 03:54:06 pm by ScoutDavid »

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Random simple java programs that actually do something useful.
« Reply #56 on: December 19, 2010, 03:55:36 pm »
JFrame is a standard part of Java and it isn't a library.
It's used to created frames. (Hence its name)
Edit: ninja'd
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Random simple java programs that actually do something useful.
« Reply #57 on: December 19, 2010, 04:05:28 pm »
I see, thanks for the info. :D

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Random simple java programs that actually do something useful.
« Reply #58 on: December 19, 2010, 04:52:20 pm »
The syntax is the same as Java, but it has more functions/commands to help you making GUI :)

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Random simple java programs that actually do something useful.
« Reply #59 on: December 19, 2010, 05:01:54 pm »
Swing is a standard part of Java, actually ;)
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.