-
Need Help!!! College project :(
Hi guys!
im wondering if any of you can help me out here. myself and a few others are trying to develop an online book ordering system for a college project. we have designed our applet ( with various buttons ) but we need to be able to link the button objects to an application form to enter details. any ideas on how to do this? the code has to be contained on the one page. we are developing the project in Jbuilder5.
here is the code below.
thanx again for all your help!
DrunkinP
/**
* Title: project
* Description:
* Copyright: Copyright (c) 2005
* Company: college practicals
* @author trish
* @version 1.0
*/
import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;
public class project extends Applet
{
Label label1;
Button buttonEnterDetails;
Button buttonUpdateDetails;
Button buttonContactAdmin;
Button buttonSearchForBook;
Button button1 = new Button();
public void init()
{
setLayout(null);
setBackground(Color.black);
setSize(800, 800); //size of applet in web page
label1 = new Label("Welcome to Books & Buy", Label.CENTER);
//label1.setFont(Font Bold);
label1.setBounds(8,8,280,40);
label1.setBackground(Color.red);
label1.setForeground(Color.white);
add(label1); // add label1 to web page
buttonEnterDetails = new Button();
buttonEnterDetails.setLabel("Enter Details");
buttonEnterDetails.setBounds(8,152,86,32);
buttonEnterDetails.setBackground(Color.red);
buttonEnterDetails.setForeground(Color.white);
add(buttonEnterDetails);
buttonUpdateDetails = new Button();
buttonUpdateDetails.setLabel("Update Details");
buttonUpdateDetails.setBounds(104,152,86,32);
buttonUpdateDetails.setBackground(Color.red);
buttonUpdateDetails.setForeground(Color.white);
add(buttonUpdateDetails);
buttonContactAdmin = new Button();
buttonContactAdmin.setLabel("ContactAdmin");
buttonContactAdmin.setBounds(200,152,86,32);
buttonContactAdmin.setBackground(Color.red);
buttonContactAdmin.setForeground(Color.white);
add(buttonContactAdmin);
buttonSearchForBook = new Button();
buttonSearchForBook.setLabel("Search");
buttonSearchForBook.setBounds(300,152,86,32);
buttonSearchForBook.setBackground(Color.red);
buttonSearchForBook.setForeground(Color.white);
add(buttonSearchForBook);
ButtonListener ourButtonListener = new ButtonListener();
buttonEnterDetails.addActionListener(ourButtonListener);
buttonUpdateDetails.addActionListener(ourButtonListener);
buttonContactAdmin.addActionListener(ourButtonListener);
buttonSearchForBook.addActionListener(ourButtonListener);
}
class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Object press = event.getSource();
if(press == buttonEnterDetails)
{
// THIS IS THE PART WHERE WE ARE GETTING PROBLEMS WITH
}}}}
-
The general idea...
I have made the outlines of one way to do this. As you will see I have
implemented the applet as a panel in a frame, but I hope that the general
idea is visible....
(if you use swing you could have a JTabbedPane w. 4 panels instead of an
initial screen w. four buttons)
PS: I don't like the null layoutmanager very much...
Code:
import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;
public class ProApplet extends Applet implements ActionListener {
Label label1;
Label label2;
Button buttonShowStartPanel;
Button buttonEnterDetails;
Button buttonUpdateDetails;
Button buttonContactAdmin;
Button buttonSearchForBook;
Button button1 = new Button();
Panel initialPanel=new Panel(null);
Panel detailsFormPanel=new Panel(null);
public static void main(String [] args) {
Frame f = new Frame("AppletTester");
f.setLayout(new GridLayout());
ProApplet applet = new ProApplet();
f.add(applet, null);
applet.init();
applet.makeInitialPanel();
applet.makeDetailsFormPanel();
applet.showInitialPanel();
f.setBounds(10,10,300,200);
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void init() {
setSize(800, 800); //size of applet in web page
}
public void showInitialPanel() {
this.removeAll();
setLayout(new GridLayout());
add(initialPanel,null);
validate();
repaint();
}
public void showDetailsPanel() {
this.removeAll();
setLayout(new GridLayout());
add(detailsFormPanel,null);
validate();
repaint();
}
private void makeDetailsFormPanel() {
detailsFormPanel.setBackground(Color.black);
label2 = new Label("Enter your details here", Label.CENTER);
label2.setBounds(8, 8, 280, 40);
label2.setBackground(Color.red);
label2.setForeground(Color.white);
detailsFormPanel.add(label1);
buttonShowStartPanel = new Button();
buttonShowStartPanel.setLabel("Show start screen");
buttonShowStartPanel.setBounds(8, 152, 86, 32);
buttonShowStartPanel.setBackground(Color.red);
buttonShowStartPanel.setForeground(Color.white);
detailsFormPanel.add(buttonShowStartPanel);
buttonShowStartPanel.addActionListener(this);
}
private void makeInitialPanel() {
initialPanel.setBackground(Color.black);
label1 = new Label("Welcome to Books & Buy", Label.CENTER);
//label1.setFont(Font Bold);
label1.setBounds(8, 8, 280, 40);
label1.setBackground(Color.red);
label1.setForeground(Color.white);
initialPanel.add(label1); // add label1 to web page
buttonEnterDetails = new Button();
buttonEnterDetails.setLabel("Enter Details");
buttonEnterDetails.setBounds(8, 152, 86, 32);
buttonEnterDetails.setBackground(Color.red);
buttonEnterDetails.setForeground(Color.white);
initialPanel.add(buttonEnterDetails);
buttonUpdateDetails = new Button();
buttonUpdateDetails.setLabel("Update Details");
buttonUpdateDetails.setBounds(104, 152, 86, 32);
buttonUpdateDetails.setBackground(Color.red);
buttonUpdateDetails.setForeground(Color.white);
initialPanel.add(buttonUpdateDetails);
buttonContactAdmin = new Button();
buttonContactAdmin.setLabel("ContactAdmin");
buttonContactAdmin.setBounds(200, 152, 86, 32);
buttonContactAdmin.setBackground(Color.red);
buttonContactAdmin.setForeground(Color.white);
initialPanel.add(buttonContactAdmin);
buttonSearchForBook = new Button();
buttonSearchForBook.setLabel("Search");
buttonSearchForBook.setBounds(300, 152, 86, 32);
buttonSearchForBook.setBackground(Color.red);
buttonSearchForBook.setForeground(Color.white);
initialPanel.add(buttonSearchForBook);
buttonEnterDetails.addActionListener(this);
buttonUpdateDetails.addActionListener(this);
buttonContactAdmin.addActionListener(this);
buttonSearchForBook.addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
Object press = event.getSource();
if (press == buttonEnterDetails) {
showDetailsPanel();
// THIS IS THE PART WHERE WE ARE GETTING PROBLEMS WITH
} else if (press == buttonShowStartPanel) {
showInitialPanel();
}
}
}
Last edited by sjalle; 03-06-2005 at 06:57 PM.
eschew obfuscation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks