Author |
Message |
Tony
|
Posted: Thu Sep 25, 2003 11:58 pm Post subject: (No subject) |
|
|
I think he means .swing
actually I wouldn't mind a good explonation of that ether |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
krishon
|
Posted: Fri Sep 26, 2003 5:07 pm Post subject: (No subject) |
|
|
most displaying and manipulating...my friend and i are think bout doin a fps (first person shooter) for a project....so i just wanna learn about displaying and manipulating...but wut we really need to know is how to make an environment...but yah...a tut on displayin and manipulating would be great! |
|
|
|
|
|
Tony
|
Posted: Fri Sep 26, 2003 5:12 pm Post subject: (No subject) |
|
|
FPS? you'd need to write up a 3D engine for that. Why not start with something a bit less graphics demanding? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
krishon
|
Posted: Fri Sep 26, 2003 5:13 pm Post subject: (No subject) |
|
|
i know...that's y i need to start nice and ez...and way b4 we start the fp's |
|
|
|
|
|
krishon
|
Posted: Sat Sep 27, 2003 9:12 pm Post subject: (No subject) |
|
|
tony, may u repost teh first solution u had b4 u editted it? thx |
|
|
|
|
|
Tony
|
Posted: Sun Sep 28, 2003 1:16 am Post subject: (No subject) |
|
|
it was just some preudo code. I didnt remember the exact syntax at that moment and I edited it after I looked it up.
it was basically just the
text.substring(0,text.indexOf(" "));
line |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
krishon
|
Posted: Sun Sep 28, 2003 9:29 am Post subject: (No subject) |
|
|
kk, thx |
|
|
|
|
|
krishon
|
Posted: Sun Sep 28, 2003 12:04 pm Post subject: (No subject) |
|
|
well heres wut i have so far...it still doesn't compile correctly....
code: | import javax.swing.JOptionPane;
class Nameshon
{
private String firstName, lastName, name, initials;
private char lastLetter;
public void getName ()
{
name = JOptionPane.showInputDialog ("Put your full name with a space between your first and last name.");
firstName = name.substring(0,text.indexOf(" "));
lastName = name.substring(text.indexOf(" ")+1);
}
public void getLetter ()
{
lastLetter = nameCharAt(name.length()/2);
}
public void getInitials ()
{
initials = firstNameCharAt(1) + lastNameCharAt (1);
}
public static void main (String args [])
{
System.out.println ("Your name is " + name + ".");
System.out.println ("Your first name is " + firstName + ".");
System.out.println ("Your last name is " + lastName + ".");
System.out.println ("The middle letter in your last name " + lastName + " is " + lastLetter + ".");
System.out.println ("Your initials are " + initials + ".");
}
} |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
rizzix
|
Posted: Sun Sep 28, 2003 1:09 pm Post subject: (No subject) |
|
|
woah! there's something terribly wrong here!
1: the main method is the only method that is called when ur program is executed. so to get ur program to work you have to call the other methods inside the main method, else no method is ever called and the variables fristName, lastName never do get set.
2: the structure and design is completely wrong. don't worry everyone get it wrong the first time with OOP languages.
by policy i'm not allowed to do the work for you. but you'll never get it if you don't see the difference between a correctly designed code and one that is relatively incorrect.
here's how i'd do it:
code: |
import javax.swing.JOptionPane;
class Nameshon
{
 private String name;
Nameshon(String pname) {
name = pname;
}
Â
 public String getFullName() {
return name;
}
Â
 public char getLetter ()
 {
   String lname = getLastName();
return lname.charAt((int)lname.length()/2);
 }
Â
 public String getInitials ()
 {
  return ((String) ("" + name.charAt(1) + name.charAt(name.length() - 1)).toUpperCase();
 }
public String getFirstName() {
return name.substring(0, name.indexOf(" "));
}
public String getLastName() {
return name.substring(name.indexOf(" ") + 1);
}
Â
 public static void main (String args [])
 {
String result = JOptionPane.showInputDialog ("Put your full name with a space between your first and last name.");
Nameshon name = new Nameshon(result);
  System.out.println ("Your name is " + name.getFullName() + ".");
  System.out.println ("Your first name is " + name.getFirstName() + ".");
  System.out.println ("Your last name is " + name.getLastName() + ".");
  System.out.println ("The middle letter in your last name is " + name.getLetter() + ".");
  System.out.println ("Your initials are " + name.getInitials() + ".");
 }
}
|
As you can see. you were treating the static method main as an instance method. You can't do that. Static methods cannot access (call) instance methods and variables. But instance methods can call and access static methods and variables.
Since a static method cannot access an instance method you'll have to treat it as though it was not part of that object. But exists within the reach of that object. In other words, the object can call it etc.. but not the other way round. This is why you need to create an object in the static method. and call it's methods.. etc..
Just compare the classes. You'll see a couple of other errors here and there.
NOTE: i haven't tested the class yet. |
|
|
|
|
|
krishon
|
Posted: Sun Sep 28, 2003 8:31 pm Post subject: (No subject) |
|
|
aha....yea.. ...well u see how bad i am, lol...k, thx for the help |
|
|
|
|
|
krishon
|
Posted: Mon Sep 29, 2003 4:51 pm Post subject: (No subject) |
|
|
one more thing....you know in the code above where you put in result for the parameter, how come it won't work with any other things....does it only work when it says result? |
|
|
|
|
|
rizzix
|
Posted: Mon Sep 29, 2003 5:20 pm Post subject: (No subject) |
|
|
no. you can pass any String object as an argument irrespective of the variable name. |
|
|
|
|
|
krishon
|
Posted: Tue Sep 30, 2003 5:50 pm Post subject: (No subject) |
|
|
k, cuzi put like theName and it didn't work...so yah |
|
|
|
|
|
tlivingston
|
Posted: Tue Sep 30, 2003 7:59 pm Post subject: (No subject) |
|
|
its cause in the notes she has it as CharAt when it should be charAt ....
(little c in char)...thats the prob |
|
|
|
|
|
krishon
|
Posted: Wed Oct 01, 2003 7:40 pm Post subject: (No subject) |
|
|
yah...stupid notes, lol |
|
|
|
|
|
|