This code is not running and throws an exception | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

This code is not running and throws an exception

import java.awt.*; class loginwindow extends Frame { loginwindow() { this.setLayout(null); Label l1 = new Label("Username :"); Label l2 = new Label("Password :"); Textfield t1 = new Textfield(20); Textfield t2 = new Textfield(20); Button b1,b2; t2.setEchoChar("*"); b1 = new Button("Submit"); b2 = new Button("Reset"); this.add(l1); this.add(t1); this.add(l2); this.add(t2); this.add(b1); this.add(b2); } public static void main(String args[]) { loginwindow obj = new loginwindow(); obj.setVisible(true); obj.setSize(400,400); obj.setTitle("My log in window"); }

26th Apr 2019, 1:01 PM
Abhinav Joshi
Abhinav Joshi - avatar
8 Antworten
+ 1
Abhinav Joshi do you have other files in your working directory
26th Apr 2019, 1:28 PM
Seniru
Seniru - avatar
0
What is the error message you got?
26th Apr 2019, 1:02 PM
Seniru
Seniru - avatar
0
Exception in thread "main" java.lang.UnsupportedOperationException: Not supported yet. at loginwindow$Textfield.<init>(loginwindow.java:58) at loginwindow$Textfield.<init>(loginwindow.java:52) at loginwindow.<init>(loginwindow.java:20) at loginwindow.main(loginwindow.java:42) C:\Users\abhin\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 1 second)
26th Apr 2019, 1:03 PM
Abhinav Joshi
Abhinav Joshi - avatar
0
*this* is not required when u r adding the component in your frame new textfield(20)?? this declaration is wrong too.. u need to add action listener for your buttons and also need to set bounds for all your components.
26th Apr 2019, 2:16 PM
kiRA
kiRA - avatar
0
kiRA Adding action listeners and setting bounds are not compulsory
26th Apr 2019, 2:19 PM
Seniru
Seniru - avatar
0
UHH! Just spotted the problem. There are no class called Textfield in awt package. It should be TextField https://docs.oracle.com/javase/7/docs/api/java/awt/TextField.html
26th Apr 2019, 2:21 PM
Seniru
Seniru - avatar
0
Sεηιrυ ραsαη then whats the point in declaring buttons if u r not even going to use them And without set bounds , there will be no components visible on the screen
26th Apr 2019, 2:38 PM
kiRA
kiRA - avatar
0
kiRA you are right. Buttons without listeners are clearly useless. But it's not mandatory. Also LayoutManager s are anothrer way of positioning things.
26th Apr 2019, 2:45 PM
Seniru
Seniru - avatar