Tau Slater

Greenhorn
+ Follow
since Jan 30, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tau Slater

Got round it a while back by down-casting int to char and vice versa. For anyone who may be interested...
14 years ago
I've been scratching my head over this one for months; I would have thought it simple enough but hey. The problem I'm having is that I want to input a UTF8 code, say \u3088, into a JOptionPane.showInput prompt, and then have a showMessageDialog come back with よ, the Japanese character. I've read through and adapted code from this tutorial:UTF encoding Tutorial and have come up with this:



So when I breakpoint it where strTest1 is set, I see "日本語文字列" which is the correct Japanese text for those utf8 char codes; But, and this is the bit that's causing me the headache, when I enter \u3088, or \u65e5 into the JOptionPane.showInput dialog, it comes back with \u3088. The problem is obviously centered around reading in the string from the showInput dialog box, as when its set explicitly in the code, it works ok.

Why is this?

The text files write "日本語文字列" (test1.txt) and "\u3088" (test2.txt) or whatever you type in; It's frustrating the hell out of me because I sense a layer of obfuscation that I'm not able to get round yet.

Do I have to go down to the byte level?

Is it utf8 / utf16 related?

Looking at the text files with a hex editor reveals that there's no byte order marker either, not that utf8 needs it explicitly, but yet again, after coming up blank when I thought I had a new angle on it, I've hit a wall... Any insight would be appreciated...
14 years ago
Haha! Victory is mine again... Fixed it after reading this:
buffered draw without flicker

Like I say, I'm still at an early stage with all this...

14 years ago
That's what I thought, but I was just checking. I've got past that now and am stuck on the text I'm displaying in the writing panel...

Edit: I've got flickering text in the writingpanel... I'm trying to debug my code but can't see what is causing the flicker - I've taken everything down to the bare minimum to get it working, as following:

The string is flickering in the JPanel - and consuming about 10% CPU (i920 Qcore, lol) so I'm doing something pretty fundamentally wrong there... Any ideas?

14 years ago
Just to check on this really, but I can override paintComponent multiple times can't I? Say for instance I have my JFrame class, and in that class, are two nested classes, DrawingPanel and WritingPanel, both extending JPanel.

For my purposes, I want to draw in DrawingPanel (can do) but I also want to do a bit of g.drawstring-ing in WritingPanel. So, if I override paintComponent in both, is that bad? I'm just having probs trying to draw anything in WritingPanel at the moment. I can't set the background colour in the same way I can on PaintPanel, for instance. Do I need to do anything different? I would have thought not nesting the classes was a good start but meh.... Sorry for newbie type questions. I'm still trying to understand this;
14 years ago
HAHA! Victory is mine! I've used some of your code Craig, but the important thing is I understand what was going on and why it didn't work. I *was* loading up the image but not creating a graphics context from it, so I used to be able to load an image and se eit, or draw one and not edit it... Fixed now - the heart of it was:


Notably, I also didn't see this as I was at first drawing with a white colour on a white background. Sometimes even the simple things can catch you out eh?... On an asides, drawing and painting in Java is a real pain isn't it? Or is it just me? I mean I whacked a program together like this in C# on visual studio in half an hour... Oh well. I'm hardly a coding guru anyway. Thanks again for your help Craig
14 years ago
Thanks a lot Craig, I notice you're using a png file as well. I'd noticed some compression artefacts in my jpg when saved, as I'd gone with the default encoding settings and not played around with it on that front, but I think I'll play around with the formats and see what I can do.

Thanks again
14 years ago
yeah I was just trying anything at that point to make it work - it's not like anything else needs to use it, but at the moment, I'm more concerned with getting a functional program than dotting the Is and crossing the Ts. I do try and observe good OO design methodology, but the truth is, I've been teaching myself Java for 10 - 12 weeks or so, not every day at that, and am very fresh in that respect. Tips always appreciated though
14 years ago
I can write my JPanel to an image, and read that image and dislpay it to the JPanel, but can't draw more or "add" to that image when it's loaded. Do I need to use a bufferedimage or will a plain "image" be ok? I assume this is GUI related as the images load and save ok. Here's what happens ideally:

1. List of items chosen.
2. Picture drawn in DrawingPanel (extends JPanel) and saved by list index
3. When the list is loaded again, the picture comes up. User can draw on it and save it again if neccessary.
4. Picture saved again.

The trouble happens when the picture is loaded up a second time. I can either write pictures the the hdd, or read them and display them... Can't do the last step

How image is stored:


The paintComponent method in PaintPanel: (where the picture is drawn - PaintPanel is a nested class, in a JFrame.)


I have a feeling the paint method isn't set up to write over an existing picture? I know the jpg quality is going to deteriorate as well; I just want to be able to re-write over a jpg when it's loaded up and save the altered image.
14 years ago
Thankyou!!! It's that syntax that got me. I'll post details later but now I can make a start on this at last! The understanding of this has come in gradual fits and starts - your piece was the final part of the puzzle I think! - well, final so far...

thank you very much
14 years ago
I'm having real trouble getting a simple paint program to work. My goal is to draw in a JPanel and save the drawing to hdd; It's only a small panel in a larger JFrame, not a drawing program, so there are only a few simple colour buttons and a clear function.

My problem is that I cannot figure out for the life of me how to override the paintComponent method; I've read the sun tutorials here: tutorial gone through literally dozens of threads like this one: paint problem and come back blank, because everytime I try to implement the code in my project there is no paintComponent method to override;

Here:


Using netbeans, I should get an "add override" message pointing to the paintComponent method shouldn't I? This is in a JFrame and I also override paint, which I've commented out for the moment as I wondered if that affected it.

General program structure:
Main class instantiates JFrame. JFrame has controls and stuff on it, including a JPanel (not paintPanel at the moment)

On the JFrame, you can draw in the JPanel as I've set it up, but I know my code is shaky and I want to sort it our by overriding the correct way; There's nothing there to override though - what am I missing???
14 years ago
Hello everyone - first post here, I'm a beginner, and have searched through the forums for something like my problem with no clear success...

So, I have an Access database, specified as a data source in control panel (as KanjiQuiz) and accessible by a small Java program that I wrote, based on code elsewhere on the web. The data in the DB is partially Japanese, and when I retrieve the Japanese data it comes back as "?" question marks.

Here's the code:



The database is 10 records of a kanji, onyomi and kunyomi and meaning - also example word here but that's not retrieved. Meaning is in English and comes back ok. I tried to pinpoint where it's going wrong, hence the string kanji line. String test = "\u3088" = よ. (yo) I've been reading about utf16 and utf8 byte ordering, I've looked at formatters and tried to parse the strings to unicode characters, which came back with 63 - ascii question mark. So, it appears it's getting question marks from the access database - I didn't know whether to post this Q here or in the DB section, but my DB connection works ok...

Failing a quick workaround or fix - can anyone suggest how I *should* be storing up to several thousand lines of data for a kanji quiz type app? eg access, mysql, txt file etc... I thought an access connection would be quicker / better than byte parsing a text file... Oh well...

Help me obi wan! lol!