Quote:
Originally Posted by Mourning Tide
Holy crap WTF does that all mean - you might wanna join and ask a computer forum, not a bodybuilding one lol
|
lol i cant believe im gonna explain all this
ok these three lines below import certain libraries of code that have already been written. the java.awt classes are for the windowing code that draws the window in the gui. the event stuff underneath is for tracking events like when a user clicks something so you can do certain other things. the javax.swing is other gui code that has already been written so you just include it in your code and then can create objects of those types to do things that you dont have to write new code for
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
this makes a class called nGame so basically you can create nGame objects whenever/wherever you want and they behave this certain way. an object has certain values/private variables and certain methods you can call on it to make it do stuff
public class nGame extends JFrame
{
these are the three things you see in the image, the text field the button you click and the pane behind them
private JTextField jTextField1;
private JButton jButton1;
private JPanel contentPane;
much of the rest is action listener and action performed code to track when a user does something on these objects like click them or type text into them. then you can have the code basically listen for these events and then you can call other code to make it behave a certain way when a user does something
hope this helps
public nGame()
{
super();
initializeComponent();
this.setVisible(true);
}
private void initializeComponent()
{
jTextField1 = new JTextField();
jButton1 = new JButton();
contentPane = (JPanel)this.getContentPane();
jTextField1.setText("Enter Username");
jTextField1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jTextField1_actionPerformed(e);
}
});
jButton1.setText("ENTER");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jButton1_actionPerformed(e);
}
});
contentPane.setLayout(null);
addComponent(contentPane, jTextField1, 175,110,112,22);
addComponent(contentPane, jButton1, 295,105,83,28);
this.setTitle("nGame - extends JFrame");
this.setLocation(new Point(81, 39));
this.setSize(new Dimension(479, 300));
}
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
private void jTextField1_actionPerformed(ActionEvent e)
{
System.out.println("\njTextField1_actionPerformed( ActionEvent e) called.");
}
private void jButton1_actionPerformed(ActionEvent e)
{
System.out.println("\njButton1_actionPerformed(Act ionEvent e) called.");
}