Go Back   Flash Flash Revolution > General Discussion > Technology
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
Old 09-8-2012, 03:20 PM   #1
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Continuing to fail at Java

So I'm still doing my Java study, which is going surprisingly slowly due to the speed of the rest of the students. Now I have to interest myself somehow.

Trying to make a Java "hiragana-notepad" that dynamically changes my latin character input into hiragana. So far I can't even get a KeyListener to work.

tl;dr code inc
Using the MVC-model + a main class

Main class (not that interesting):
Code:
package start;

import javax.swing.JFrame;
import view.GUI;

public class Main {
	public static void main(String[] args) {
		GUI a = new GUI();
		a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		a.setVisible(true);
	}
}


GUI class (works properly):
Code:
package view;

import java.awt.*;
import javax.swing.*;
import controller.HiraganaController;

public class GUI extends JFrame{
	private static final long serialVersionUID = 1L;
	private HiraganaController KeyCon = new HiraganaController(this);
	
	public GUI(){
		Container window = getContentPane();
		setTitle("Hiragana Notepad");
		setSize(640,480);
		
		JPanel mainpanel = new JPanel();
		mainpanel.setLayout(null);
		mainpanel.setBackground(Color.DARK_GRAY);
		mainpanel.setBounds(0,0,640,480);
		window.add(mainpanel);
		
		JTextArea area = new JTextArea();
		area.setBounds(5,5,614,432);
		area.setLineWrap(true);
		area.addKeyListener(KeyCon);
		mainpanel.add(area);
	}
}


HiraganaController class (no object is made, program doesn't even get to the switch):
Code:
package controller;

import java.awt.event.*;
import view.GUI;
import model.HiraganaConfig;

public class HiraganaController implements KeyListener{
	private GUI gui;
	String prev;
	
	public HiraganaController(GUI gui){
		this.gui = gui;
	}
	
	public void keyPressed(KeyEvent e){}
	public void keyReleased(KeyEvent e){}
	public void keyTyped(KeyEvent e){
		int key = e.getKeyCode();
		switch(key){
		case KeyEvent.VK_A:
			System.out.println("Works");
		break;
		case KeyEvent.VK_E:
			
		break;
		case KeyEvent.VK_I:
			
		break;
		case KeyEvent.VK_O:
			
		break;
		case KeyEvent.VK_U:
			
		break;
		}
	}
}


HiraganaConfig class (Just a husk of code, will come later):
Code:
package model;

import view.GUI;

public class HiraganaConfig{
	private GUI gui = new GUI();
	String syl;
	
	public String aConfig(String prev){
		return syl;
	}
	public String eConfig(String prev){
		return syl;
	}
	public String iConfig(String prev){
		return syl;
	}
	public String oConfig(String prev){
		return syl;
	}
	public String uConfig(String prev){
		return syl;
	}
}


When I run the program, it starts the GUI fine and I can type text in the JTextArea as much as my heart desires. However, when I type an "a", it doesn't do the System.out.println() described in the controller class.
The KeyListener should do a check whenever I type a vowel, I just don't know how to initiate that from within the GUI class...

Any help?
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.

Last edited by SKG_Scintill; 09-8-2012 at 04:40 PM..
SKG_Scintill is offline   Reply With Quote
Old 09-9-2012, 01:28 AM   #2
Patashu
FFR Simfile Author
Retired StaffFFR Simfile Author
 
Patashu's Avatar
 
Join Date: Apr 2006
Location: we traced the call...it's coming from inside the house
Age: 33
Posts: 8,609
Send a message via AIM to Patashu Send a message via MSN to Patashu Send a message via Yahoo to Patashu
Default Re: Continuin to fail at Java

Dumb question but have you tried using KeyReleased instead of KeyTyped?
__________________
Patashu makes Chiptunes in Famitracker:
http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png
Patashu is offline   Reply With Quote
Old 09-9-2012, 05:02 AM   #3
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: Continuin to fail at Java

Well **** me silly, that actually worked xD

I'll keep using this thread in case I stumble upon other things
Until I finish the program that is

Thanks Patashu!
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.
SKG_Scintill is offline   Reply With Quote
Old 09-9-2012, 06:19 AM   #4
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: Continuin to fail at Java

Can you make a method with a switch() using an int[]?

"int vow" is the KeyCode of a vowel pressed
"int prev" is the KeyCode of the consonant before the vowel

Code:
public void hirConfig(int prev, int vow){
	int[] sym = {prev, vow};
	switch(sym){
	case {87,65}:
		System.out.println("わ");
	break;
	}
}
Obviously this doesn't work, it tells me so:
Quote:
Cannot switch on a value of type int[]. Only convertible int values or enum constants are permitted
Is it possible some other way, though?
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.

Last edited by SKG_Scintill; 09-9-2012 at 06:22 AM..
SKG_Scintill is offline   Reply With Quote
Old 09-9-2012, 07:28 AM   #5
Patashu
FFR Simfile Author
Retired StaffFFR Simfile Author
 
Patashu's Avatar
 
Join Date: Apr 2006
Location: we traced the call...it's coming from inside the house
Age: 33
Posts: 8,609
Send a message via AIM to Patashu Send a message via MSN to Patashu Send a message via Yahoo to Patashu
Default Re: Continuin to fail at Java

Don't use a case switch, use a http://docs.oracle.com/javase/1.4.2/...Hashtable.html
For bonus credit, populate the Hashtable from a file instead of in code, so you can alter it without recompiling
__________________
Patashu makes Chiptunes in Famitracker:
http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png
Patashu is offline   Reply With Quote
Old 09-10-2012, 06:48 AM   #6
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: Continuin to fail at Java

Tried another route, and I have a weird NullPointerException

Code:
package controller;

import java.awt.event.*;
import model.HiraganaConfig;
import view.GUI;

public class HiraganaController implements KeyListener{
	private GUI gui;
	private HiraganaConfig config;
	private int prev;
	
	public HiraganaController(GUI gui){
		this.gui = gui;
	}
	
	public void keyPressed(KeyEvent e){}
	public void keyReleased(KeyEvent e){
		int key = e.getKeyCode();
		
		switch(key){
		default:
			prev = e.getKeyCode();
		break;
		case KeyEvent.VK_A:
			config.hirConfig(key,prev);
		break;
		case KeyEvent.VK_E:
			config.hirConfig(key,prev);
		break;
		case KeyEvent.VK_I:
			config.hirConfig(key,prev);
		break;
		case KeyEvent.VK_O:
			config.hirConfig(key,prev);
		break;
		case KeyEvent.VK_U:
			config.hirConfig(key,prev);
		break;
		}
	}
	public void keyTyped(KeyEvent e){}
}
When I type "ba", it gives me a NullPointerException
I put "System.out.println(key);" and "System.out.println(prev);" before "config.hirConfig(key,prev);" and it DOES give the KeyCodes of both B and A.

I tried giving the parameters manually:
Code:
config.hirConfig(65,66);
But to no avail; still a NullPointerException.

It says it's in line 25, which is the line I just gave.
Not a clue where it is coming from. What is null?
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.

Last edited by SKG_Scintill; 09-10-2012 at 06:51 AM..
SKG_Scintill is offline   Reply With Quote
Old 09-10-2012, 08:31 AM   #7
Patashu
FFR Simfile Author
Retired StaffFFR Simfile Author
 
Patashu's Avatar
 
Join Date: Apr 2006
Location: we traced the call...it's coming from inside the house
Age: 33
Posts: 8,609
Send a message via AIM to Patashu Send a message via MSN to Patashu Send a message via Yahoo to Patashu
Default Re: Continuin to fail at Java

private HiraganaConfig config;
This variable is null since you never initialize it, and since it's private it couldn't be initialized outside of the file either.
__________________
Patashu makes Chiptunes in Famitracker:
http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png
Patashu is offline   Reply With Quote
Old 09-10-2012, 08:58 AM   #8
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: Continuin to fail at Java

Thankfully it's all small problems :P
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.
SKG_Scintill is offline   Reply With Quote
Old 09-10-2012, 09:50 AM   #9
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: Continuin to fail at Java

Back so soon? Yes, quite...

It's pretty much the last step, and it's starting to look like Murphy's Law.

So all there's left for me to do is to get the right symbol in the JTextArea (I made two now, code is coming up), except it doesn't set it when I do setText.

GUI code:
Code:
package view;

import java.awt.*;
import javax.swing.*;
import controller.HiraganaController;

public class GUI extends JFrame{
	private static final long serialVersionUID = 1L;
	private HiraganaController KeyCon = new HiraganaController(this);
	public JTextArea hirarea = new JTextArea();
	
	public GUI(){
		Container window = getContentPane();
		setTitle("Hiragana Notepad");
		setSize(640,480);
		
		JPanel mainpanel = new JPanel();
		mainpanel.setLayout(null);
		mainpanel.setBounds(0,0,640,480);
		window.add(mainpanel);
		
		JTextArea area = new JTextArea();
		area.setBounds(5,5,614,300);
		area.setBorder(BorderFactory.createMatteBorder(3,3,3,3,Color.DARK_GRAY));
		area.setLineWrap(true);
		area.addKeyListener(KeyCon);
		mainpanel.add(area);
		
		hirarea.setBounds(5,311,614,125);
		hirarea.setBorder(BorderFactory.createMatteBorder(3,3,3,3,Color.DARK_GRAY));
		hirarea.setLineWrap(true);
		mainpanel.add(hirarea);
	}
}


HiraganaConfig code:
Code:
package model;

import view.GUI;

public class HiraganaConfig{
	private GUI gui = new GUI();
	
	public void hirConfig(int key, int prev){
		switch(key){
		case 65:
			switch(prev){
			case 1:
				gui.hirarea.setText("I ");
			break;
			case 66:
				gui.hirarea.setText("Don't ");
			break;
			}
		break;
		case 69:
			
		break;
		case 73:
			
		break;
		case 79:
			
		break;
		case 85:
			
		break;
		}
	}
}


If I put sys.out's for key and prev in cases 1 and 66 (1 is the default value of prev) it does print them correctly. The only thing not working is the "gui.hirarea.setText();", which is strange as it does work when I put "hirarea.setText();" in the GUI class.

Also, setText() isn't really what I need I think, as one symbol would overwrite the other; I want (lol I so demandin') it to type the symbol next to the other.
In the end I might just do it all over with .getText() instead of KeyEvent, but I can't just give up now.
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.
SKG_Scintill is offline   Reply With Quote
Old 09-10-2012, 03:16 PM   #10
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: Continuin to fail at Java

Triple post, figured it out

Didn't have to make a new GUI in the config class and make the hirarea static

Well then... off to make it with a .getText()
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.
SKG_Scintill is offline   Reply With Quote
Old 09-11-2012, 08:38 AM   #11
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: Continuin to fail at Java

Finished, had to redo most of the code, those switch/cases were having too many exceptions to work. I made it with a systematic list for the code to run down, much easier.

View:
Code:
package view;

import java.awt.*;
import javax.swing.*;
import controller.HiraganaController;

public class GUI extends JFrame{
	private static final long serialVersionUID = 1L;
	private HiraganaController KeyCon = new HiraganaController(this);
	public static JTextArea area = new JTextArea();
	public static JTextArea hirarea = new JTextArea();
	
	public GUI(){
		Container window = getContentPane();
		setTitle("Hiragana Notepad");
		setSize(640,480);
		
		JPanel mainpanel = new JPanel();
		mainpanel.setLayout(null);
		mainpanel.setBackground(Color.DARK_GRAY);
		mainpanel.setBounds(0,0,640,480);
		window.add(mainpanel);
		
		area.setBounds(5,5,614,300);
		area.setLineWrap(true);
		area.addKeyListener(KeyCon);
		mainpanel.add(area);
		
		hirarea.setBounds(5,311,614,124);
		hirarea.setLineWrap(true);
		mainpanel.add(hirarea);
	}
}

Control:
Code:
package controller;

import java.awt.event.*;
import model.SymConfig;
import view.GUI;

public class HiraganaController implements KeyListener{
	public HiraganaController(GUI gui){}
	
	public void keyPressed(KeyEvent e){}
	public void keyReleased(KeyEvent e){
		SymConfig config = new SymConfig();
		GUI.hirarea.setText(GUI.area.getText());
		config.hirConfig();
	}
	public void keyTyped(KeyEvent e){}
}

Model:
Code:
package model;

import view.GUI;

public class SymConfig{
	public void hirConfig(){
		String input = GUI.area.getText().toLowerCase();

//--	A
		input = input.replace("ba","ば");
		input = input.replace("da","だ");
		input = input.replace("ga","が");
		input = input.replace("ha","は");
		input = input.replace("ja","じゃ");
		input = input.replace("kya","きゃ");
		input = input.replace("ka","か");
		input = input.replace("ma","ま");
		input = input.replace("na","な");
		input = input.replace("pa","ぱ");
		input = input.replace("ra","ら");
		input = input.replace("sa","さ");
		input = input.replace("ta","た");
		input = input.replace("wa","わ");
		input = input.replace("ya","や");
		input = input.replace("za","ざ");
		input = input.replace("a","あ");
		
//--	E
		input = input.replace("be","べ");
		input = input.replace("de","で");
		input = input.replace("ge","げ");
		input = input.replace("he","へ");
		input = input.replace("ke","け");
		input = input.replace("me","め");
		input = input.replace("ne","ね");
		input = input.replace("pe","ぺ");
		input = input.replace("re","れ");
		input = input.replace("se","せ");
		input = input.replace("te","て");
		input = input.replace("ze","ぜ");
		input = input.replace("e","え");
		
//--	I
		input = input.replace("bi","び");
		input = input.replace("gi","ぎ");
		input = input.replace("chi","ち");
		input = input.replace("shi","し");
		input = input.replace("hi","ひ");
		input = input.replace("ji","じ");
		input = input.replace("ki","き");
		input = input.replace("mi","み");
		input = input.replace("ni","に");
		input = input.replace("pi","ぴ");
		input = input.replace("ri","り");
		input = input.replace("i","い");
		
//--	O
		input = input.replace("bo","ぼ");
		input = input.replace("do","ど");
		input = input.replace("go","ご");
		input = input.replace("ho","ほ");
		input = input.replace("jo","じょ");
		input = input.replace("ko","こ");
		input = input.replace("mo","も");
		input = input.replace("no","の");
		input = input.replace("po","ぽ");
		input = input.replace("ro","ろ");
		input = input.replace("so","そ");
		input = input.replace("to","と");
		input = input.replace("wo","を");
		input = input.replace("yo","よ");
		input = input.replace("zo","ぞ");
		input = input.replace("o","お");
		
//--	U
		input = input.replace("bu","ぶ");
		input = input.replace("fu","ふ");
		input = input.replace("gu","ぐ");
		input = input.replace("ju","じゅ");
		input = input.replace("ku","く");
		input = input.replace("mu","む");
		input = input.replace("nu","ぬ");
		input = input.replace("pu","ぷ");
		input = input.replace("ru","る");
		input = input.replace("tsu","つ");
		input = input.replace("su","す");
		input = input.replace("vu","ゔ");
		input = input.replace("yu","ゆ");
		input = input.replace("zu","ず");
		input = input.replace("u","う");
		
//--	N
		input = input.replace("n","ん");
		GUI.hirarea.setText(input);
	}
}


Now I'm off to make it so you can use capslock to convert a substring to Katakana

P.S: Is there any way to make code more elegant?
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.

Last edited by SKG_Scintill; 09-11-2012 at 08:47 AM..
SKG_Scintill is offline   Reply With Quote
Old 09-11-2012, 04:02 PM   #12
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: Continuin to fail at Java

I'm the only one using my own thread, I don't mind.

Can you check if a String contains two of the same chars next to eachother?
For example: the word "ganbatte" in romaji has to print "がんばって" instead of "がんばtて" which it does now.
I could just make it .replace("t","っ"), but I'd have to do it for every consonant...

Any help?
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.
SKG_Scintill is offline   Reply With Quote
Old 09-11-2012, 04:44 PM   #13
UserNameGoesHere
FFR Veteran
FFR Veteran
 
UserNameGoesHere's Avatar
 
Join Date: May 2008
Posts: 1,114
Send a message via AIM to UserNameGoesHere
Default Re: Continuin to fail at Java

That's tricky and not anything Java-specific. What you are doing is known as parsing. Essentially you are writing a parser that converts from romaji to Japanese characters. Without knowing Japanese myself, I'm not going to be any good at telling you the correctness of that particular conversion.

What I will tell you is you need to make sure to handle all your cases. Also it matters in what order things are evaluated. Substitutions which take more precedence over others need to come earlier in the list.

Parsing can be a difficult and tricky topic and there are entire programming languages written only for writing parsers.

http://en.wikipedia.org/wiki/Parsing
__________________
Quote:
Originally Posted by Crashfan3 View Post
Man, what would we do without bored rednecks?
[SIGPIC][/SIGPIC]
UserNameGoesHere is offline   Reply With Quote
Old 09-13-2012, 10:42 AM   #14
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: Continuin to fail at Java

Did it with a for loop:
Code:
for(int x = 2; x < input.toCharArray().length + 1; x++){
	if(input.substring(x-2,x-1).equals(input.substring(x-1,x))){
		String sub = input.substring(x-2,x);
		input = input.replace(sub,"っ" + sub.charAt(0));
	}
}
I tried adding another if-statement in the loop for the hiraganagaeshi, but they cancel eachother out; it's one or the other.
Code:
for(int x = 4; x < input.toCharArray().length + 1; x++){
	if(input.substring(x-2,x-1).equals(input.substring(x-1,x))){
		String sub = input.substring(x-2,x);
		input = input.replace(sub,"っ" + sub.charAt(0));
	}
	if(input.substring(x-4,x-2).equals(input.substring(x-2,x))){
		String sub = input.substring(x-4,x);
		input = input.replace(sub,sub.substring(x-2,x) + "ゝ");
	}
}
Can you make it so both ifs work at the same time?
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.

Last edited by SKG_Scintill; 09-13-2012 at 10:55 AM..
SKG_Scintill is offline   Reply With Quote
Old 09-13-2012, 05:27 PM   #15
Patashu
FFR Simfile Author
Retired StaffFFR Simfile Author
 
Patashu's Avatar
 
Join Date: Apr 2006
Location: we traced the call...it's coming from inside the house
Age: 33
Posts: 8,609
Send a message via AIM to Patashu Send a message via MSN to Patashu Send a message via Yahoo to Patashu
Default Re: Continuin to fail at Java

In general it's a bad idea to modify something you're iterating over if it causes its length to change. Scan the input string, building the output string separately (use StringBuilder for efficiency) a character at a time.
__________________
Patashu makes Chiptunes in Famitracker:
http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png
Patashu is offline   Reply With Quote
Old 09-14-2012, 03:01 AM   #16
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: Continuin to fail at Java

That seems a bit redundant, that way I'd need a StringBuffer in my for-loop.
I checked the StringBuffer and it doesn't have a method that checks all substrings of a given length existing in the String, which is what I made with the for-loop.
Nevertheless, I'm only a starter at Java with my "less than half a year of class"-experience (first year only had one trimester Java). If I'm overlooking something important, do tell ;)

Edit: I get the idea that "you can better do it the right way the first time, as in the future you may come across problems if you do it this way", but I approach every problem differently and learn experimentally.
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.

Last edited by SKG_Scintill; 09-14-2012 at 03:04 AM..
SKG_Scintill is offline   Reply With Quote
Old 09-14-2012, 03:30 AM   #17
Patashu
FFR Simfile Author
Retired StaffFFR Simfile Author
 
Patashu's Avatar
 
Join Date: Apr 2006
Location: we traced the call...it's coming from inside the house
Age: 33
Posts: 8,609
Send a message via AIM to Patashu Send a message via MSN to Patashu Send a message via Yahoo to Patashu
Default Re: Continuin to fail at Java

Quote:
Originally Posted by SKG_Scintill View Post
That seems a bit redundant, that way I'd need a StringBuffer in my for-loop.
No, my suggestion is you read the original string and build the stringbuilder with every character you decide does not need any further translation. That way you're not modifying the same thing you're reading over.

EDIT: Wait, maybe I don't understand the problem yet. If the problem is that you want aaaa to be turned into bb before it notices the first aa and turns it into c, well, why not run the second 'if' statement in a for loop, then run the first 'if' statement in a second for loop?
__________________
Patashu makes Chiptunes in Famitracker:
http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png

Last edited by Patashu; 09-14-2012 at 03:33 AM..
Patashu is offline   Reply With Quote
Old 09-14-2012, 05:21 AM   #18
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: Continuin to fail at Java

Well yeah, making a second for-loop is the easy way out. I'm trying to make code more elegant step by step.
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.
SKG_Scintill is offline   Reply With Quote
Old 09-15-2012, 04:53 AM   #19
UserNameGoesHere
FFR Veteran
FFR Veteran
 
UserNameGoesHere's Avatar
 
Join Date: May 2008
Posts: 1,114
Send a message via AIM to UserNameGoesHere
Default Re: Continuin to fail at Java

Example:
Just make sure if aaaa is something special, and aa is also something special, that input of aaaa will work correctly.

Suppose aaaa -> b
Suppose aa -> c

Will input of aaaa go to b or will it go to cc?
Well, that depends entirely on the order. In this case you probably want the longer match first, i.e. earlier in the list.

You just have to make sure it works for every case. Think of possible cases which might trip it up, etc...

Not knowing Japanese, I can't tell you what these cases may be in this particular case/etc... but know that order very well may matter and it may be possible to get stuck in infinite loops if two rules mutually depend on each other, or similar.

Seriously, hit up that wikipedia link for a background on the subject. Then read the related entries as well. I think that you have not, and I recommend that you do so if you care about the topic. Again, parsing is a tricky topic and there are entire programming languages only for writing parsers.
__________________
Quote:
Originally Posted by Crashfan3 View Post
Man, what would we do without bored rednecks?
[SIGPIC][/SIGPIC]
UserNameGoesHere is offline   Reply With Quote
Old 09-16-2012, 06:54 AM   #20
Patashu
FFR Simfile Author
Retired StaffFFR Simfile Author
 
Patashu's Avatar
 
Join Date: Apr 2006
Location: we traced the call...it's coming from inside the house
Age: 33
Posts: 8,609
Send a message via AIM to Patashu Send a message via MSN to Patashu Send a message via Yahoo to Patashu
Default Re: Continuin to fail at Java

Quote:
Originally Posted by SKG_Scintill View Post
Well yeah, making a second for-loop is the easy way out. I'm trying to make code more elegant step by step.
If the algorithm is logically expressed by 'do this loop, then do this loop', why not have two loops?
__________________
Patashu makes Chiptunes in Famitracker:
http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png
Patashu is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 07:21 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution