Creating a basic Notepad Application
#16
Posted 06 February 2009 - 11:41 AM
very nice tutorial!!!
I wanted to change the title when the user saves a file, so I did this:
created a static variable: private static Notepad app;
added this in the save event: app.setTitle(save.getSelectedFile().getName() + " - Notepad");
and this in the main: app = new Notepad();
do you know a better way to do this?
thanks
#17
Posted 19 February 2009 - 10:37 PM
joezim007, on 24 Jan, 2009 - 11:49 AM, said:
If I recall correctly, the AWT components (no J prefix) use the operating system's built-in functions to draw components. So if you use those they will mesh with whatever operating system the code is run on. The Swing (J prefix) components, on the other hand, are all native Java components. So your application will look consistent between operating systems.
Swing is newer than AWT, but I don't know if Sun has stopped updating the AWT components.
This post has been edited by 5thWall: 19 February 2009 - 10:38 PM
#18
Posted 16 April 2009 - 04:44 PM
This post has been edited by makarei: 16 April 2009 - 04:45 PM
#19
Posted 10 April 2010 - 06:33 PM
makarei, on 16 April 2009 - 05:44 PM, said:
If I were you I would look on Youtube, Google, and the Java snippets of the website.
#20
Posted 16 June 2010 - 05:22 AM
#21 Guest_andrew*
Posted 20 August 2010 - 03:13 AM
I just learn java this morning and had an assignment like this, im kinda lost
#23
Posted 22 August 2010 - 07:32 PM
Whenever I exited the program using the "close" menu item, the window would disappear but the process would continue to run. I kept having to manually terminate the program from the command line. I modified the relevant portion of the event handler to say:
// if the source of the event was our "close" option
if(e.getSource() == this.close){
this.dispose(); // dispose all resources and close the application
System.exit(0);
}
And this fixed everything (I can actually get rid of the this.dispose(); line altogether and it works fine too). I did this on an Ubuntu linux computer - could that have anything to do with it? Is "this.dispose();" supposed to terminate the program or just visually remove the window and all its resources?
Did anyone else run into this?
#24
Posted 09 September 2010 - 03:16 PM
I'm working on Windows 7 and I can save those files perfectly, but when I want to open that same file the console says that is don't have permissions to open the file. How can I overdue that?
#25 Guest_elvis*
Posted 22 September 2010 - 06:16 AM
hi
i am compiling and getting no error using cmd prompt but when i run i get :
C:\test\Notepad\src\notepad>javac notepad.java
C:\test\Notepad\src\notepad>java notepad
Exception in thread "main" java.lang.NoClassDefFoundError: notepad (wrong name:
Notepad)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: notepad. Program will exit.
and using netbeans when i run i get :
run:
java.lang.NoClassDefFoundError: notepad/Main
Caused by: java.lang.ClassNotFoundException: notepad.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: notepad.Main. Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
pls help , what silly mistake am i doing
#26 Guest_elvis*
Posted 22 September 2010 - 06:49 AM
should be java Notepad
(not notepad)
thx very much for such explanation
#27
Posted 05 October 2010 - 10:09 PM
e.g the menubar and then the colde
Menu and then the code..
same as for the rest...
I try to join the codes but I'm lost I can't figure it out which code goes where....Sorry too dumb in java
#28
Posted 05 December 2010 - 05:29 AM
I had to put the "included" and Notepad class in a separate .java file and to put main in a class called ProgramTest, in a separate .java file. Then compile the project and run the ProgramTest.
You made me happy
Digihash, on 09 September 2010 - 02:16 PM, said:
I'm working on Windows 7 and I can save those files perfectly, but when I want to open that same file the console says that is don't have permissions to open the file. How can I overdue that?
Save on desktop or on a non-system drive OR you can run the program with administrator privileges
#29
Posted 12 December 2010 - 07:44 AM
elvis, on 22 September 2010 - 05:16 AM, said:
hi
i am compiling and getting no error using cmd prompt but when i run i get :
C:\test\Notepad\src\notepad>javac notepad.java
C:\test\Notepad\src\notepad>java notepad
Exception in thread "main" java.lang.NoClassDefFoundError: notepad (wrong name:
Notepad)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: notepad. Program will exit.
and using netbeans when i run i get :
run:
java.lang.NoClassDefFoundError: notepad/Main
Caused by: java.lang.ClassNotFoundException: notepad.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: notepad.Main. Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
pls help , what silly mistake am i doing
did you copy and paste it? and if you did that did you delete the line numbers in front of the program after you coppied and pasted it?
#30
Posted 13 December 2010 - 06:36 AM
DADDYCARDONA, on 12 December 2010 - 08:44 AM, said:
elvis, on 22 September 2010 - 05:16 AM, said:
hi
i am compiling and getting no error using cmd prompt but when i run i get :
C:\test\Notepad\src\notepad>javac notepad.java
C:\test\Notepad\src\notepad>java notepad
Exception in thread "main" java.lang.NoClassDefFoundError: notepad (wrong name:
Notepad)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: notepad. Program will exit.
and using netbeans when i run i get :
run:
java.lang.NoClassDefFoundError: notepad/Main
Caused by: java.lang.ClassNotFoundException: notepad.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: notepad.Main. Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
pls help , what silly mistake am i doing
did you copy and paste it? and if you did that did you delete the line numbers in front of the program after you coppied and pasted it?
No one should ever copy and paste when reading a tutorial. If you do how are you going to understand the code and learn it.
|
|







MultiQuote




|