• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Need Help with my Applet code

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does not work, could anyone tell me what's wrong.

<html>
<head>
<title>JMX Management</title>
</head>
<body>
<APPLET CODE="LoginView.class" HEIGHT=600 WEIGHT=600>
Text displayed by browsers that are not Java-enabled.
</APPLET>

</body>
</html>
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;

public class LoginView extends Applet {

private Image background;
private static int widthVar;
private static int heightVar;
/** Creates new form JFrame */
public LoginView() {
initComponents();
}
private void initComponents() {
pnlTop = new javax.swing.JPanel();
pnlBottom = new javax.swing.JPanel();
lblUser = new javax.swing.JLabel();
txtUser = new javax.swing.JTextField(10);
lblPassword = new javax.swing.JLabel();
txtPassword = new javax.swing.JPasswordField(10);
btnEnter = new javax.swing.JButton();
btnClose = new javax.swing.JButton();
pnlMain = new javax.swing.JPanel();
lblLogin = new javax.swing.JLabel();
pnlMessage = new javax.swing.JPanel();
lblMessage = new javax.swing.JLabel();

btnEnter.setForeground(java.awt.Color.blue);
btnClose.setForeground(java.awt.Color.blue);

btnClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCloseActionPerformed(evt);
}
});

btnEnter.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEnterActionPerformed(evt);
}
});

//addWindowListener(new java.awt.event.WindowAdapter() {
// public void windowClosing(java.awt.event.WindowEvent evt) {
// exitForm(evt);
// }
// });

background = getToolkit().getImage( this.getClass().getResource(
"images/email_sign.gif" ) );
try {
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(background, 0);
tracker.waitForID(0);
} catch( Exception e ){}

lblLogin.setText("NewTrade Login ");
lblLogin.setForeground(java.awt.Color.blue);

lblMessage.setText(" ");
pnlMessage.add(lblMessage);

lblUser.setText("username:");
pnlTop.add(lblUser);
pnlTop.add(txtUser);

lblPassword.setText("password:");
pnlTop.add(lblPassword);

txtPassword.setEchoChar('*');
pnlTop.add(txtPassword);

btnEnter.setText("Enter");
pnlBottom.add(btnEnter);

btnClose.setText("Exit");
pnlBottom.add(btnClose);

// Place the buttons in the tabbing order
txtPassword.setNextFocusableComponent(btnEnter);
btnEnter.setNextFocusableComponent(btnClose);
btnClose.setNextFocusableComponent(txtUser);

this.setLayout(new GridBagLayout());
GridBagConstraints c=new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.gridx=1; c.gridy=0;
this.add(pnlMain, c);
c.gridwidth = GridBagConstraints.RELATIVE;
c.gridx=1; c.gridy=1;
this.add(pnlTop, c);
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridx=1; c.gridy=2;
this.add(pnlBottom, c);
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridx=1; c.gridy=3;
this.add(pnlMessage, c);
}

private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {
//create the yes/no dialog:
int n = JOptionPane.showConfirmDialog(this, "Are you sure you want to exit?", "company", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
System.exit(0);
} else if (n == JOptionPane.NO_OPTION) { }
}

private void btnEnterActionPerformed(java.awt.event.ActionEvent evt) {
// Add your handling code here:
String user = this.txtUser.getText();
String password = this.txtPassword.getText(); }
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/* public static void main(String args[]) {
LoginView mv = new LoginView();
Dimension dd = Toolkit.getDefaultToolkit().getScreenSize ();
Dimension m = mv.getSize ();
dd.width -= m.width;
dd.height -= m.height;
dd.width /= 2;
dd.height /= 2;
widthVar=dd.width;
heightVar=dd.height;
mv.show();
mv.setBounds((dd.width-30), (dd.height-30), 500, 200);
mv.setVisible (true);
}*/

public void paint(Graphics g) {
super.paint(g);
g.drawImage( background, 0, 15, null );
}
// Variables declaration
private javax.swing.JPanel pnlTop;
private javax.swing.JPanel pnlBottom;
private javax.swing.JLabel lblUser;
private javax.swing.JTextField txtUser;
private javax.swing.JLabel lblPassword;
private javax.swing.JPasswordField txtPassword;
private javax.swing.JButton btnEnter;
private javax.swing.JButton btnClose;
private javax.swing.JPanel pnlMain;
private javax.swing.JLabel lblLogin;
private javax.swing.JPanel pnlMessage;
private javax.swing.JLabel lblMessage;
// Variables declaration
}
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I tried this example and was able to get it working in Netscape6.but it failed in IE5.5.
i think theres some thing to do with security settings related to applets.Also i got it to working ,after removing code related to that paint.
 
What's that smell? Hey, sniff this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic