Java Notepad

Status
This thread has been locked.

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
Hello MCM,

I am currently learning Java and so to practice I decided to make a notepad.

I have come across a few problems, which I cannot figure out how to solve;

Problem #1

Your file is saved to a .txt, so next time you open it, it will be in a notepad, instead of the application, I would like to fix this. I want it so that you double click the file and it automatically opens the Java notepad.

Code:

Problem #2

Upon clicking "New", it asks you if you're sure that you want to clear the text area. If you click yes, it sets the text to "". However, if you click no, it does the same thing, even though I tried to make a string (String x = t.getText(), t.setText(x)). It didn't work. How can I make it so that clicking "No" will simply close the JOptionPane and keep the text?

Code:

Problem #3

The margin will not work on the JTextArea.

Code: t.setMargin( new Insets(10,10,10,10) );

Problem #4

The last problem is that when you "Open" (via the JMenu) the .txt, the lines (/n) are not saved, e.g. all the text is printed out onto one line. How do I fix this? I could not ask this question to google as it is quite specific and I did not know how to word it.



If these questions are "stupid" then bare in mind, I am still learning. I have already looked at StackOverflow but to no avail.

If any of you want to add my skype it is Mixtape.Archie, if you want to teach me Bukkit API / give me links to helpful sources then please do!


Thank you very much,

Archie.



 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)

Jack

Retired Moderator
Supreme
Feedback score
11
Posts
1,210
Reactions
1,462
Resources
0
Problem #1 isn't to do with your program, it's to do with Windows.

bh219VT.png


You'll have to Choose default program... and navigate to your own application.
You'll also have to add code which allows you to accept command-line arguments (when you open somefile.txt with Notepad, you're actually running notepad.exe "somefile.txt" so you will have to load the file from argv[1]).

Edit:
I haven't done enough GUI work in Java to help you with the rest, sorry.
 

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
Problem #1 isn't to do with your program, it's to do with Windows.

bh219VT.png


You'll have to Choose default program... and navigate to your own application.
You'll also have to add code which allows you to accept command-line arguments (when you open somefile.txt with Notepad, you're actually running notepad.exe "somefile.txt" so you will have to load the file from argv[1]).
I guess I'll leave that for now then!
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)

Infinite

Premium
Feedback score
0
Posts
364
Reactions
171
Resources
0
int dialogButton = JOptionPane.YES_NO_OPTION;
Problem #2
that's not the clicked button
i think thats the problem but don't quote me on it; like jack, i rarely use guis
 

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
int dialogButton = JOptionPane.YES_NO_OPTION;
Problem #2
that's not the clicked button
i think thats the problem but don't quote me on it; like jack, i rarely use guis
It's opening a GUI asking you Yes or No. I put if it == yes then set the text to "". If == no, what method do I use to keep the text, at the minute it sets it to "".
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)

Maccas

MineCorner Founder
Premium
Feedback score
1
Posts
1,446
Reactions
597
Resources
0
Or you can download Eclipse or IDE and learn within the actual application instead of Notepad. I suggest also watching various tutorials on YouTube.
 

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
I can't find the answers anywhere, and no, I'm not coding on a notepad haha. Can anyone help though?
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)
Status
This thread has been locked.
Top