Help with Building a GUI
I'm trying to activate my buttons "Calculate" and "Exit" for my Box Volume Calculator GUI I created with NetBeans. I get the error message "if without else".
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
if (evt.getSource()==btnCalculate)
doCalculate();
else if (evt.getSource()==btnExit)
System.exit(0);
void doCalculate() {
double height;
double width;
double depth;
double volumeCalc;
height =Double.parseDouble(txtHeight.getText());
width =Double.parseDouble(txtWidth.getText());
depth =Double.parseDouble(txtDepth.getText());
volumeCalc =height*width*depth;
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
if (evt.getSource()==btnCalculate)
doCalculate();
else if (evt.getSource()==btnExit)
System.exit(0);
}//GEN-LAST:event_jButton2ActionPerformed
* @param args the command line arguments
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new BoxVolCalc().setVisible(true);
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
// End of variables declaration//GEN-END:variables
}}}
Where is the error generated? It's perfectly legal to have an if without an else.
As an aside, why would you even put the duplicate if/else blocks in? You have two buttons and two listeners - you'd only need an if/else if you were dumb enough to wire all your listeners to all your buttons. Bizarre.
Similar Messages
-
Hi all,
I need a little help with building a new comp and any help will be appericiated.
My wife is a video editor and she needs a new CPU.
She is editing HD films from various cameras (she have several clients).
The budget is around 1500-2000$ for the CPU without screens and software which she already owns.
She is working with CS5.5 and using windows 7 pro 64bit.
I read quite a lot in the past few days and I ended up more confused then I was, this is the setup which I thought of:
CPU: I was thinking about the i7 960 3.2 (310$) or the i7 2600k (330$).
MB: Asus p6x8D 1366 ddr 1600
Graphics: Gigabyte nVidia GTX460 1gb gddr5 (210$) or gtx560(230$) the 570 is way off the budget (440$)
BLURAY: Pioneer BDR-206
RAM: I don't know really.. I was thinking about 12gb but I am cluless about it.
Power: AX 850W Gold Active PFC 12cm Fan Modular (No particular reason, when I'll know my final setup I'll check the power I need with http://www.extreme.outervision.com/psucalculatorlite.jsp).
Case: Antec / Thermaltake, No idea which model..
OS HDD: I'm still puzzled weather to go for the small (60gb) ssd for the OS and programs or go for a 7200 rpm hd.
HDD: W.D Caviar black 1tb 7200 rpm, 64mb, Sata III * 4 with raid on board (Raid 0 or Raid 5? - I'll save it for another thread).
Coolers: Help needed
Any help will be more then welcomed.
Regards,
Eliran.While waiting for a specific answer, you might read these recent discussions
http://forums.adobe.com/thread/910208
http://forums.adobe.com/thread/907698
http://forums.adobe.com/thread/762381
http://forums.adobe.com/thread/906848
http://forums.adobe.com/thread/912120
http://forums.adobe.com/thread/912119
And one specific... SSD is high $$ and there is a thread concerning problems... forum search for ssd will find at least 2 message threads about using ssd or not -
Help with Times Table GUI applet
Hello,
I need help with an applet which inputs an integer from the user and displays the appropiate times table up to times 10 eg; user input 5 - display shows
5 time 1 is 5
5 times 2 is 10
5 times 10 is 50.
I have only managedt o get the display to show one statement eg 5 times 1 - I have tried using a for loop to show the whole table - but unlike a print statement each time the loop goes round it overwrites the data in the display box with the new data - any help would be much appreciated.
Note: it is for a programming course year 1 exercise - so I can only use basic constructs or loops to achieve this. Thanks in advance! Heres what I have so far:
import java.applet.* ;
import java.awt.* ;
import java.awt.event.* ;
public class TimesTableApplet extends Applet implements ActionListener
// Declare the GUI components globally
Label titleLabel, whichTableLabel ;
TextField whichTableBox, resultBox ;
Button showTableButton, clearButton ;
// Declare integer variables for holdind the number input by the user,
// the times number, and the result number
int whichTable, times=1, result ;
// Declare variables to hold string versions of the three integer variables
// above, for placing in the TextFields
String whichTableString, timesString, resultString ;
public void init ()
// Create the Labels
titleLabel = new Label ( "Times Table" ) ;
whichTableLabel = new Label ( "Which Table?" ) ;
// Create the TextFields
whichTableBox = new TextField ( 5 ) ;
resultBox = new TextField ( 30 ) ;
// Create the Buttons
showTableButton = new Button ( "Show Table" ) ;
clearButton = new Button ( "Clear" ) ;
// Add the components to the applet window
add ( titleLabel ) ;
add ( whichTableLabel ) ;
add ( whichTableBox ) ;
whichTableBox.addActionListener ( this ) ;
add ( resultBox ) ;
resultBox.setEditable ( false ) ;
add ( showTableButton ) ;
showTableButton.addActionListener ( this ) ;
add ( clearButton ) ;
clearButton.addActionListener ( this ) ;
} // End of init method
public void actionPerformed ( ActionEvent event )
// Find out which button generated the event
String arg = event.getActionCommand () ;
// If the user clicks the clear button, clear the whichTableBox and
// resultBox
if ( arg.equals ( "Clear" ) )
whichTableBox.setText ( "" ) ;
resultBox.setText ( "" ) ;
else
try
// Try extracting a string from the whichTableBox ( the users input )
// and converting it to an integer
whichTableString = whichTableBox.getText () ;
whichTable = Integer.parseInt ( whichTableString ) ;
// Clear status box
showStatus ( "" ) ;
// If the user clicks the showTableButton, display the appropiate
// times table up to times 10
if ( arg.equals ( "Show Table" ) ) ;
result = whichTable * times ;
timesString = Integer.toString ( times ) ;
resultString = Integer.toString ( result ) ;
resultBox.setText ( whichTableString + " times " + timesString + " is " + resultString ) ;
} // End of try block
catch ( NumberFormatException entry )
// Display error message and clear whichTableBox
showStatus ( "Error: Invalid Input - not an integer!" ) ;
whichTableBox.setText ( "" ) ;
} // End of catch block
} // End of else statement
} // End of actionPerformed method
} // End of classuse this code, please arrange your User interface correctly.
* TimesTableApplet.java
* Created on March 12, 2007, 12:08 PM
* @author cc.woon
import java.applet.* ;
import java.awt.* ;
import java.awt.event.* ;
public class TimesTableApplet extends Applet implements ActionListener
// Declare the GUI components globally
Label titleLabel, whichTableLabel ;
TextField whichTableBox ;
TextArea resultBox;
Button showTableButton, clearButton ;
// Declare integer variables for holdind the number input by the user,
// the times number, and the result number
int whichTable, times=1, result ;
// Declare variables to hold string versions of the three integer variables
// above, for placing in the TextFields
String whichTableString, timesString, resultString ;
public void init ()
// Create the Labels
titleLabel = new Label ( "Times Table" ) ;
whichTableLabel = new Label ( "Which Table?" ) ;
// Create the TextFields
whichTableBox = new TextField ( 5 ) ;
resultBox = new TextArea() ;
// Create the Buttons
showTableButton = new Button ( "Show Table" ) ;
clearButton = new Button ( "Clear" ) ;
// Add the components to the applet window
add ( titleLabel ) ;
add ( whichTableLabel ) ;
add ( whichTableBox ) ;
whichTableBox.addActionListener ( this ) ;
add ( resultBox ) ;
resultBox.setEditable ( false ) ;
add ( showTableButton ) ;
showTableButton.addActionListener ( this ) ;
add ( clearButton ) ;
clearButton.addActionListener ( this ) ;
} // End of init method
public void actionPerformed ( ActionEvent event )
// Find out which button generated the event
String arg = event.getActionCommand () ;
// If the user clicks the clear button, clear the whichTableBox and
// resultBox
if ( arg.equals ( "Clear" ) )
whichTableBox.setText ( "" ) ;
resultBox.setText ( "" ) ;
else
try
// Try extracting a string from the whichTableBox ( the users input )
// and converting it to an integer
whichTableString = whichTableBox.getText () ;
whichTable = Integer.parseInt ( whichTableString ) ;
// Clear status box
showStatus ( "" ) ;
// If the user clicks the showTableButton, display the appropiate
// times table up to times 10
if ( arg.equals ( "Show Table" ) ) ;
result = whichTable * times ;
timesString = Integer.toString ( times ) ;
String output = "";
for(int i =1;i<=10;i++){
output += whichTable +" times "+i + ": "+(i*whichTable)+"\n";
resultString = Integer.toString ( result ) ;
//resultBox.setText ( whichTableString + " times " + timesString + " is " + resultString ) ;
resultBox.setText ( output) ;
} // End of try block
catch ( NumberFormatException entry )
// Display error message and clear whichTableBox
showStatus ( "Error: Invalid Input - not an integer!" ) ;
whichTableBox.setText ( "" ) ;
} // End of catch block
} // End of else statement
} // End of actionPerformed method
} // End of class -
Help with building flash files for streaming
I filmed a product demonstration for a client who wanted to put it on his website. I edited the footage in PremPro CS4 and exported to Media Encoder as F4V file format. After encoding imported footage into CS4 Encore, created timeline, chose, Flash from Format and swf for output. Progressive Download which allows video to begin playing as it is downloaded (I believe), chose destinations and settings. After transcoding I had 1 file folder, Sources that contained the following files _PGC_Bpge_entryPoint_Bbp_1.f4v, and then 3 separate files, *not* in the file folder called Sources. They are
AuthoredContent.xml, FlashDVD.swf, and Index.html.
I submitted all files to client who gave them to web designer. Designer said these were the wrong files and he could not use them. I called designer and basically he said I didn't know what I was doing. I told him he needed all files to put up the flash video. Anyway, am I missing something, doing something wrong? Are there other files he needs? He said he only needed 1 file. Or is it the designer? I'm not thin skinned so if it's me please tell me so, so I don't make the same errors. Thanks. All suggestions/comments are appreciated!<The client wants a control player, i.e. play, stop, pause, etc., that's it, so the viewer can simply provide the function themselves. This is similar to youtube, blogger, etc.
The web designer can use what you provided, which does what you describe the client wanting. But the web designer may need to integrate what Encore provided onto a web page, and the client may not have made the expectations clear and may not know what is needed. As I said, the Encore to flash player gives almost no options for the player controls and colors etc may be problems.
<Encore did encode the f4v file. When I exported from PremPro what preset should I hve chosen -- mpeg2 DVD, flv/f4v. So the only file he needs in addition to what I gave him is the original f4v file?
I don't know whether the f4v you exported from Premiere was progressive. The f4v from Encore might be fine, or you might need to export from Premiere again.
The other issue is that some "player" with controls needs to be provided by you or the web designer (who may have an issue with the client not getting the designer to lay all this out to begin with). There are several threads about "flv players" you might check out. Does the client have video on his site already? If so, you can figure out what they are using, and it will help with your process.
should I have chosen "flash server" instead of "progressive". i must admit i never did this before. other clients just have me post it to youtube and provide them with embed code.
It depends on what they want. -
i have msi pc with build in cam
i dont remembar wath the taip m series somthing i have cure 2 duo cpu t5750 2 gb ram 320 gb
giforce 8400
now i dont find any driver for the cam and the pc dos'nt know the cam....
i run vista 32bit
any one can halp me pleas!!!:(:(:(You have some notebook or? Read >>Posting Guide<<
-
Help with building a JTree using tree node and node renderers
Hi,
I am having a few problems with JTree's. basically I want to build JTree from a web spider. The webspide searches a website checking links and stores the current url that is being processed as a string in the variable msg. I wan to use this variable to build a JTree in a new class and then add it to my GUI. I have created a tree node class and a renderer node class, these classes are built fine. can someone point me in the direction for actually using these to build my tree in a seperate class and then displaying it in a GUI class?
*nodeRenderer.java
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.net.*;
public class nodeRenderer extends DefaultTreeCellRenderer
implements TreeCellRenderer
public static Icon icon= null;
public nodeRenderer() {
icon = new ImageIcon(getClass().getResource("icon.gif"));
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(
tree, value, sel,
expanded, leaf, row,
hasFocus);
treeNode node = (treeNode)(((DefaultMutableTreeNode)value).getUserObject());
if(icon != null) // set a custom icon
setOpenIcon(icon);
setClosedIcon(icon);
setLeafIcon(icon);
return this;
*treeNode.java
*this is the class to represent a node
import javax.swing.*;
import javax.swing.tree.*;
import java.util.*;
import java.net.*;
* Class used to hold information about a web site that has
* been searched by the spider class
public class treeNode
*Url from the WebSpiderController Class
*that is currently being processed
public String msg;
treeNode(String urlText)
msg = urlText;
String getUrlText()
return msg;
//gui.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class gui extends JFrame implements Runnable
*declare variable, boolean
*thread, a object and a center
*pane
protected URL urlInput;
protected Thread bgThread;
protected boolean run = false;
protected WebSpider webSpider;
public gui()
*create the gui here
setTitle("Testing Tool");
setSize(600,600);
//add Buttons to the tool bar
start.setText("Start");
start.setActionCommand("Start");
toolBar.add(start);
ButtonListener startListener = new ButtonListener();
start.addActionListener(startListener);
cancel.setText("Cancel");
cancel.setActionCommand("Cancel");
toolBar.add(cancel);
ButtonListener cancelListener = new ButtonListener();
cancel.addActionListener(cancelListener);
close.setText("Close");
close.setActionCommand("Close");
toolBar.add(close);
ButtonListener closeListener = new ButtonListener();
close.addActionListener(closeListener);
//creat a simple form
urlLabel.setText("Enter URL:");
urlLabel.setBounds(100,36,288,24);
formTab.add(urlLabel);
url.setBounds(170,36,288,24);
formTab.add(url);
current.setText("Currently Processing: ");
current.setBounds(100,80,288,24);
formTab.add(current);
//add scroll bars to the error messages screen and website structure
errorPane.setAutoscrolls(true);
errorPane.setHorizontalScrollBarPolicy(javax.swing.
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
errorPane.setVerticalScrollBarPolicy(javax.swing.
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
errorPane.setOpaque(true);
errorTab.add(errorPane);
errorPane.setBounds(0,0,580,490);
errorText.setEditable(false);
errorPane.getViewport().add(errorText);
errorText.setBounds(0,0,600,550);
treePane.setAutoscrolls(true);
treePane.setHorizontalScrollBarPolicy(javax.swing.
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
treePane.setVerticalScrollBarPolicy(javax.swing.
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
treePane.setOpaque(true);
treeTab.add(treePane);
treePane.setBounds(0,0,580,490);
treeText.setEditable(false);
treePane.getViewport().add(treeText);
treeText.setBounds(0,0,600,550);
//create the tabbed window
centerPane.setBorder(new javax.swing.border.EtchedBorder());
formTab.setLayout(null);
errorTab.setLayout(null);
treeTab.setLayout(null);
centerPane.addTab("Search Parameters", formTab);
centerPane.addTab("Error Messages", errorTab);
centerPane.addTab("Website Structure", treeTab);
//add the tool bar and tabbed pane
getContentPane().add(toolBar, java.awt.BorderLayout.NORTH);
getContentPane().add(centerPane, java.awt.BorderLayout.CENTER);
*create the tool bar pane, a center pane, add the buttons,
*labels, tabs, a text field for user input here
javax.swing.JPanel toolBar = new javax.swing.JPanel();
javax.swing.JButton start = new javax.swing.JButton();
javax.swing.JButton cancel = new javax.swing.JButton();
javax.swing.JButton close = new javax.swing.JButton();
javax.swing.JTabbedPane centerPane = new javax.swing.JTabbedPane();
javax.swing.JPanel formTab = new javax.swing.JPanel();
javax.swing.JLabel urlLabel = new javax.swing.JLabel();
javax.swing.JLabel current = new javax.swing.JLabel();
javax.swing.JTextField url = new javax.swing.JTextField();
javax.swing.JPanel errorTab = new javax.swing.JPanel();
javax.swing.JTextArea errorText = new javax.swing.JTextArea();
javax.swing.JScrollPane errorPane = new javax.swing.JScrollPane();
javax.swing.JPanel treeTab = new javax.swing.JPanel();
javax.swing.JTextArea treeText = new javax.swing.JTextArea();
javax.swing.JScrollPane treePane = new javax.swing.JScrollPane();
javax.swing.JTree searchTree = new javax.swing.JTree();
*show the gui
public static void main(String args[])
(new gui()).setVisible(true);
*listen for the button presses and set the
*boolean flag depending on which button is pressed
class ButtonListener implements ActionListener
public void actionPerformed(ActionEvent event)
Object object = event.getSource();
if (object == start)
run = true;
startActionPerformed(event);
if (object == cancel)
run = false;
startActionPerformed(event);
if (object == close)
System.exit(0);
*this method is called when the start or
*cancel button is pressed.
void startActionPerformed (ActionEvent event)
if (run == true && bgThread == null)
bgThread = new Thread(this);
bgThread.start();
if (run == false && bgThread != null)
webSpider.cancel();
*this mehtod will start the background thred.
*the background thread is required so that the
*GUI is still displayed
public void run()
try
webSpider = new WebSpider(this);
webSpider.clear();
urlInput = new URL(url.getText());
webSpider.addURL(urlInput);
webSpider.run();
bgThread=null;
catch (MalformedURLException e)
addressError addErr = new addressError();
addErr.addMsg = "URL ERROR - PLEASE CHECK";
SwingUtilities.invokeLater(addErr);
*this method is called by the web spider
*once a url is found. Validation of navigation
*happens here.
public boolean urlFound(URL urlInput,URL url)
CurrentlyProcessing pro = new CurrentlyProcessing();
pro.msg = url.toString();
SwingUtilities.invokeLater(pro);
if (!testLink(url))
navigationError navErr = new navigationError();
navErr.navMsg = "Broken Link "+url+" caused on "+urlInput+"\n";
return false;
if (!url.getHost().equalsIgnoreCase(urlInput.getHost()))
return false;
else
return true;
*this method is called internally to check
*that a link works
protected boolean testLink(URL url)
try
URLConnection connection = url.openConnection();
connection.connect();
return true;
catch (IOException e)
return false;
*this method is called when an error is
*found.
public void URLError(URL url)
*this method is called when an email
*address is found
public void emailFound(String email)
/*this method will update any errors found inc
*address errors and broken links
class addressError implements Runnable
public String addMsg;
public void run()
errorText.append(addMsg);
current.setText("Currently Processing: "+ addMsg);
class navigationError implements Runnable
public String navMsg;
public void run()
errorText.append(navMsg);
*this method will update the currently
*processing field on the GUI
class CurrentlyProcessing implements Runnable
public String msg;
public void run()
current.setText("Currently Processing: " + msg );
//webspider.java
import java.util.*;
import java.net.*;
import java.io.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax.swing.tree.*;
import javax.swing.*;
*this class implements the spider.
public class WebSpider extends HTMLEditorKit
*make a collection of the URL's
protected Collection urlErrors = new ArrayList(3);
protected Collection urlsWaiting = new ArrayList(3);
protected Collection urlsProcessed = new ArrayList(3);
//report URL's to this class
protected gui report;
*this flag will indicate whether the process
*is to be cancelled
protected boolean cancel = false;
*The constructor
*report the urls to the wui class
public WebSpider(gui report)
this.report = report;
*get the urls from the above declared
*collections
public Collection getUrlErrors()
return urlErrors;
public Collection getUrlsWaiting()
return urlsWaiting;
public Collection getUrlsProcessed()
return urlsProcessed;
* Clear all of the collections.
public void clear()
getUrlErrors().clear();
getUrlsWaiting().clear();
getUrlsProcessed().clear();
*Set a flag that will cause the begin
*method to return before it is done.
public void cancel()
cancel = true;
*add the entered url for porcessing
public void addURL(URL url)
if (getUrlsWaiting().contains(url))
return;
if (getUrlErrors().contains(url))
return;
if (getUrlsProcessed().contains(url))
return;
/*WRITE TO LOG FILE*/
log("Adding to workload: " + url );
getUrlsWaiting().add(url);
*process a url
public void processURL(URL url)
try
/*WRITE TO LOGFILE*/
log("Processing: " + url );
// get the URL's contents
URLConnection connection = url.openConnection();
if ((connection.getContentType()!=null) &&
!connection.getContentType().toLowerCase().startsWith("text/"))
getUrlsWaiting().remove(url);
getUrlsProcessed().add(url);
log("Not processing because content type is: " +
connection.getContentType() );
return;
// read the URL
InputStream is = connection.getInputStream();
Reader r = new InputStreamReader(is);
// parse the URL
HTMLEditorKit.Parser parse = new HTMLParse().getParser();
parse.parse(r,new Parser(url),true);
catch (IOException e)
getUrlsWaiting().remove(url);
getUrlErrors().add(url);
log("Error: " + url );
report.URLError(url);
return;
// mark URL as complete
getUrlsWaiting().remove(url);
getUrlsProcessed().add(url);
log("Complete: " + url );
*start the spider
public void run()
cancel = false;
while (!getUrlsWaiting().isEmpty() && !cancel)
Object list[] = getUrlsWaiting().toArray();
for (int i=0;(i<list.length)&&!cancel;i++)
processURL((URL)list);
* A HTML parser callback used by this class to detect links
protected class Parser extends HTMLEditorKit.ParserCallback
protected URL urlInput;
public Parser(URL urlInput)
this.urlInput = urlInput;
public void handleSimpleTag(HTML.Tag t,MutableAttributeSet a,int pos)
String href = (String)a.getAttribute(HTML.Attribute.HREF);
if((href==null) && (t==HTML.Tag.FRAME))
href = (String)a.getAttribute(HTML.Attribute.SRC);
if (href==null)
return;
int i = href.indexOf('#');
if (i!=-1)
href = href.substring(0,i);
if (href.toLowerCase().startsWith("mailto:"))
report.emailFound(href);
return;
handleLink(urlInput,href);
public void handleStartTag(HTML.Tag t,MutableAttributeSet a,int pos)
handleSimpleTag(t,a,pos); // handle the same way
protected void handleLink(URL urlInput,String str)
try
URL url = new URL(urlInput,str);
if (report.urlFound(urlInput,url))
addURL(url);
catch (MalformedURLException e)
log("Found malformed URL: " + str);
*log the information of the spider
public void log(String entry)
System.out.println( (new Date()) + ":" + entry );
I have a seperate class for parseing the HTML. Any help would be greatly appreciated
mrvHi Sorry to be a pain again,
I have re worked the gui class so it looks like this now:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class gui extends JFrame implements Runnable
*declare variable, boolean
*thread, a object and a center
*pane
protected URL urlInput;
protected Thread bgThread;
protected boolean run = false;
protected WebSpider webSpider;
public String msgInfo;
public String brokenUrl;
public String goodUrl;
public String deadUrl;
protected DefaultMutableTreeNode rootNode;
protected DefaultTreeModel treeModel;
public gui()
*create the gui here
setTitle("Testing Tool");
setSize(600,600);
//add Buttons to the tool bar
start.setText("Start");
start.setActionCommand("Start");
toolBar.add(start);
ButtonListener startListener = new ButtonListener();
start.addActionListener(startListener);
cancel.setText("Cancel");
cancel.setActionCommand("Cancel");
toolBar.add(cancel);
ButtonListener cancelListener = new ButtonListener();
cancel.addActionListener(cancelListener);
close.setText("Close");
close.setActionCommand("Close");
toolBar.add(close);
ButtonListener closeListener = new ButtonListener();
close.addActionListener(closeListener);
//creat a simple form
urlLabel.setText("Enter URL:");
urlLabel.setBounds(100,36,288,24);
formTab.add(urlLabel);
url.setBounds(170,36,288,24);
formTab.add(url);
current.setText("Currently Processing: ");
current.setBounds(100,80,288,24);
formTab.add(current);
//add scroll bars to the error messages screen and website structure
errorPane.setAutoscrolls(true);
errorPane.setHorizontalScrollBarPolicy(javax.swing.
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
errorPane.setVerticalScrollBarPolicy(javax.swing.
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
errorPane.setOpaque(true);
errorTab.add(errorPane);
errorPane.setBounds(0,0,580,490);
errorText.setEditable(false);
errorPane.getViewport().add(errorText);
errorText.setBounds(0,0,600,550);
treePane.setAutoscrolls(true);
treePane.setHorizontalScrollBarPolicy(javax.swing.
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
treePane.setVerticalScrollBarPolicy(javax.swing.
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
treePane.setOpaque(true);
treeTab.add(treePane);
treePane.setBounds(0,0,580,490);
treeText.setEditable(false);
treePane.getViewport().add(treeText);
treeText.setBounds(0,0,600,550);
//JTree
// NEW CODE
rootNode = new DefaultMutableTreeNode("Root Node");
treeModel = new DefaultTreeModel(rootNode);
treeModel.addTreeModelListener(new MyTreeModelListener());
tree = new JTree(treeModel);
tree.setEditable(true);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setShowsRootHandles(true);
treeText.add(tree);
//create the tabbed window
centerPane.setBorder(new javax.swing.border.EtchedBorder());
formTab.setLayout(null);
errorTab.setLayout(null);
treeTab.setLayout(null);
centerPane.addTab("Search Parameters", formTab);
centerPane.addTab("Error Messages", errorTab);
centerPane.addTab("Website Structure", treeTab);
//add the tool bar and tabbed pane
getContentPane().add(toolBar, java.awt.BorderLayout.NORTH);
getContentPane().add(centerPane, java.awt.BorderLayout.CENTER);
*create the tool bar pane, a center pane, add the buttons,
*labels, tabs, a text field for user input here
javax.swing.JPanel toolBar = new javax.swing.JPanel();
javax.swing.JButton start = new javax.swing.JButton();
javax.swing.JButton cancel = new javax.swing.JButton();
javax.swing.JButton close = new javax.swing.JButton();
javax.swing.JTabbedPane centerPane = new javax.swing.JTabbedPane();
javax.swing.JPanel formTab = new javax.swing.JPanel();
javax.swing.JLabel urlLabel = new javax.swing.JLabel();
javax.swing.JLabel current = new javax.swing.JLabel();
javax.swing.JTextField url = new javax.swing.JTextField();
javax.swing.JPanel errorTab = new javax.swing.JPanel();
javax.swing.JTextArea errorText = new javax.swing.JTextArea();
javax.swing.JScrollPane errorPane = new javax.swing.JScrollPane();
javax.swing.JPanel treeTab = new javax.swing.JPanel();
javax.swing.JTextArea treeText = new javax.swing.JTextArea();
javax.swing.JScrollPane treePane = new javax.swing.JScrollPane();
javax.swing.JTree tree = new javax.swing.JTree();
*show the gui
public static void main(String args[])
(new gui()).setVisible(true);
*listen for the button presses and set the
*boolean flag depending on which button is pressed
class ButtonListener implements ActionListener
public void actionPerformed(ActionEvent event)
Object object = event.getSource();
if (object == start)
run = true;
startActionPerformed(event);
if (object == cancel)
run = false;
startActionPerformed(event);
if (object == close)
System.exit(0);
*this method is called when the start or
*cancel button is pressed.
void startActionPerformed (ActionEvent event)
if (run == true && bgThread == null)
bgThread = new Thread(this);
bgThread.start();
//new line of code
treeText.addObject(msgInfo);
if (run == false && bgThread != null)
webSpider.cancel();
*this mehtod will start the background thred.
*the background thread is required so that the
*GUI is still displayed
public void run()
try
webSpider = new WebSpider(this);
webSpider.clear();
urlInput = new URL(url.getText());
webSpider.addURL(urlInput);
webSpider.run();
bgThread = null;
catch (MalformedURLException e)
addressError addErr = new addressError();
addErr.addMsg = "URL ERROR - PLEASE CHECK";
SwingUtilities.invokeLater(addErr);
*this method is called by the web spider
*once a url is found. Validation of navigation
*happens here.
public boolean urlFound(URL urlInput,URL url)
CurrentlyProcessing pro = new CurrentlyProcessing();
pro.msg = url.toString();
SwingUtilities.invokeLater(pro);
if (!testLink(url))
navigationError navErr = new navigationError();
navErr.navMsg = "Broken Link "+url+" caused on "+urlInput+"\n";
brokenUrl = url.toString();
return false;
if (!url.getHost().equalsIgnoreCase(urlInput.getHost()))
return false;
else
return true;
*this method is returned if there is no link
*on a web page, e.g. there us a dead end
public void urlNotFound(URL urlInput)
deadEnd dEnd = new deadEnd();
dEnd.dEMsg = "No links on "+urlInput+"\n";
deadUrl = urlInput.toString();
*this method is called internally to check
*that a link works
protected boolean testLink(URL url)
try
URLConnection connection = url.openConnection();
connection.connect();
goodUrl = url.toString();
return true;
catch (IOException e)
return false;
*this method is called when an error is
*found.
public void urlError(URL url)
*this method is called when an email
*address is found
public void emailFound(String email)
/*this method will update any errors found inc
*address errors and broken links
class addressError implements Runnable
public String addMsg;
public void run()
current.setText("Currently Processing: "+ addMsg);
errorText.append(addMsg);
class navigationError implements Runnable
public String navMsg;
public void run()
errorText.append(navMsg);
class deadEnd implements Runnable
public String dEMsg;
public void run()
errorText.append(dEMsg);
*this method will update the currently
*processing field on the GUI
public class CurrentlyProcessing implements Runnable
public String msg;
//new line
public String msgInfo = msg;
public void run()
current.setText("Currently Processing: " + msg );
* NEW CODE
* NEED THIS CODE SOMEWHERE
* treeText.addObject(msgInfo);
public DefaultMutableTreeNode addObject(Object child)
DefaultMutableTreeNode parentNode = null;
TreePath parentPath = tree.getSelectionPath();
if (parentPath == null)
parentNode = rootNode;
else
parentNode = (DefaultMutableTreeNode)
(parentPath.getLastPathComponent());
return addObject(parentNode, child, true);
public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
Object child)
return addObject(parent, child, false);
public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
Object child,boolean shouldBeVisible)
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
if (parent == null)
parent = rootNode;
treeModel.insertNodeInto(childNode, parent, parent.getChildCount());
if (shouldBeVisible)
tree.scrollPathToVisible(new TreePath(childNode.getPath()));
return childNode;
public class MyTreeModelListener implements TreeModelListener
public void treeNodesChanged (TreeModelEvent e)
DefaultMutableTreeNode node;
node = (DefaultMutableTreeNode)
(e.getTreePath().getLastPathComponent());
try
int index = e.getChildIndices()[0];
node = (DefaultMutableTreeNode)
(node.getChildAt(index));
catch (NullPointerException exc)
public void treeNodesInserted(TreeModelEvent e)
public void treeStructureChanged(TreeModelEvent e)
public void treeNodesRemoved(TreeModelEvent e)
I beleive that this line of code is required:
treeText.addObject(msgInfo);
I have placed it where the action events start the spider, but i keep getting this error:
cannot resolve symbol
symbol : method addObject (java.lang.String)
location: class javax.swing.JTextArea
treeText.addObject(msgInfo);
Also the jtree is not showing the window that I want it to and I am not too sure why. could you have a look to see why? i think it needs a fresh pair of eyes.
Many thanks
MrV -
Perhaps this was missed by the group but here goes:
I am slogging thru a dynamic PHP tutorial but I cant continue without losing some understanding of the process due to ?
I am trying to complete the following:
Building your first dynamic website – Part 2: Developing the back end
However,
my Insert record form dialog (below) looks like this, and I need to change both 'title' and 'blog_entry' values (as shown above), but I cannot make that choice in my form.
I am using DW CC with the Deprecated Server Behavior from DMX zone.
I have made sure my results match the tutorial, but I cant get past the above inconsistency in functionality.
Any help would be appreciated.
Thanks folks!The Columns area indicates which form field is used to insert a value in each column. Although the post_id and updated columns are listed as getting no value, their values are generated automatically by the database.
Check that the title and blog_entry columns are being assigned the correct values. If either is marked as getting no value, it means that you have spelled the names of the form fields differently from the column names. Correct this by selecting the column name in the Columns area and selecting the form field's name from the Value pop-up menu.
Nancy O. -
Help with a simple GUI.
I am totally new to building GUI's. Everything I have picked up I did so online. From what I have learned this should work, but it throws all sorts of exceptions when I run it.
package com.shadowconcept.mcdougal;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class NavSystemGUI extends JApplet implements ActionListener
String citylist[] = {"Birmingham", "Tuscaloosa", "Atlanta", "Montgomery", "Macon", "Mobile", "Tallahassee", "Ashburn", "Lake City", "Ocala", "Orlando", "Daytona Beach", "Jacksonville", "Savannah"};
NavigationSystem N1 = new NavigationSystem();
JLabel startposition = new JLabel("Starting Position");
JLabel endposition = new JLabel("Ending Posiiton");
JLabel choice = new JLabel("Make a Choice");
JComboBox startselection = new JComboBox(citylist);
JComboBox endselection = new JComboBox(citylist);
ButtonGroup choices = new ButtonGroup();
JRadioButton DFS = new JRadioButton("Depth-First Search");
JRadioButton BFS = new JRadioButton("Breadth-First Search");
JRadioButton shortestpath = new JRadioButton("Find the Shortest Path");
JButton button = new JButton("Execute");
String Start, End;
public void init()
Container con = getContentPane();
con.setLayout(new FlowLayout());
choices.add(DFS);
DFS.setSelected(true);
choices.add(BFS);
choices.add(shortestpath);
con.add(startposition);
//startposition.setLocation(10, 20);
con.add(startselection);
//startselection.setLocation(50, 20);
startselection.addActionListener(this);
con.add(endposition);
//endposition.setLocation(10, 40);
con.add(endselection);
//endselection.setLocation(50, 40);
endselection.addActionListener(this);
con.add(choice);
//choice.setLocation(10, 60);
con.add(DFS);
DFS.addActionListener(this);
con.add(BFS);
BFS.addActionListener(this);
con.add(shortestpath);
shortestpath.addActionListener(this);
con.add(button);
button.addActionListener(this);
startselection.requestFocus();
Start = startselection.getName();
End = endselection.getName();
public void actionPerformed(ActionEvent e) {
if(e.getSource() == button){
if(DFS.isSelected()){
N1.DFS(Start, End);
if(BFS.isSelected()){
N1.BFS(Start, End);
if(shortestpath.isSelected()){
N1.shortestpath(Start, End);
}rhm54 wrote:
I am totally new to building GUI's. Everything I have picked up I did so online. From what I have learned this should work, but it throws all sorts of exceptions when I run it.It compiles and runs fine for me. Perhaps your problems are with the NavigationSystem class? But I agree with Hunter: show your error messages and somehow indicate the lines in your code that cause the errors. I often find that reposting the code with comments indicating the offending lines works best. Good luck. -
Help with a better GUI??
hi everyone!!
i am thinking for a better GUI i have already made..earlier my GUI was not reflecting any changes but with the help and suggestions by many of you i have tried to change it..but i still find it is not reflecting to be a good interface.i really need some help..i am hereby posting the code ..hope to get a good GUI than i have..
Thanks a lot
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
public class front3 extends JFrame
JRadioButton split,zip,rename,unzip;
ButtonGroup radioGroup;
public front3()
Container c = getContentPane();
c.setLayout(new GridLayout(0,1));
c.setBackground(Color. cyan);
setSize(530,120);
setResizable(false); // to disable the maximize button
ImageIcon ip= new ImageIcon("title.jpg");
JLabel j1=new JLabel("Choose the operation to be done :",ip,JLabel.CENTER);
j1.setBackground(Color.red);
c.add(j1);
ImageIcon ii= new ImageIcon("split.jpg");
split=new JRadioButton("Splitter",ii,false);
split.setBackground(Color.cyan);
ImageIcon ij= new ImageIcon("zip.jpg");
zip=new JRadioButton("Zipper",ij,false);
zip.setBackground(Color.cyan);
ImageIcon ik= new ImageIcon("rename.jpg");
rename=new JRadioButton("Rename all",ik,false);
rename.setBackground(Color.cyan);
ImageIcon il= new ImageIcon("unzip.jpg");
unzip=new JRadioButton("unzip",il,false);
unzip.setBackground(Color.cyan);
c.add (split);
c.add(zip);
c.add(unzip);
c.add(rename);
// create logical relationship between JRadioButtons
radioGroup = new ButtonGroup();
radioGroup.add(split );
radioGroup.add( zip);
radioGroup.add(rename );
radioGroup.add( unzip);
// setPosition(250,250);
setTitle("FILE UTILITY SOFTWARE");
setSize(300,500);
setVisible(true);
split.addItemListener(new ItemListener()
public void itemStateChanged(ItemEvent event)
if(split.isSelected())
Gui file = new Gui();
zip.addItemListener(new ItemListener()
public void itemStateChanged(ItemEvent event)
if(zip.isSelected())
zipping file = new zipping();
unzip.addItemListener(new ItemListener()
public void itemStateChanged(ItemEvent event)
if(unzip.isSelected())
decompress file = new decompress();
rename.addItemListener(new ItemListener()
public void itemStateChanged(ItemEvent event)
if(rename.isSelected())
rename file = new rename();
public static void main(String args[])
front3 f=new front3();
f.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e)
System.exit(0);
}simply run this code to see the GUI-
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
public class front33 extends JFrame
JRadioButton split,zip,rename,unzip;
ButtonGroup radioGroup;
public front33()
Container c = getContentPane();
c.setLayout(new GridLayout(0,1));
c.setBackground(Color. cyan);
setSize(530,120);
setResizable(false); // to disable the maximize button
ImageIcon ip= new ImageIcon("title.jpg");
JLabel j1=new JLabel("Choose the operation to be done :",ip,JLabel.CENTER);
j1.setBackground(Color.red);
c.add(j1);
ImageIcon ii= new ImageIcon("split.jpg");
split=new JRadioButton("Splitter",ii,false);
split.setBackground(Color.cyan);
ImageIcon ij= new ImageIcon("zip.jpg");
zip=new JRadioButton("Zipper",ij,false);
zip.setBackground(Color.cyan);
ImageIcon ik= new ImageIcon("rename.jpg");
rename=new JRadioButton("Rename all",ik,false);
rename.setBackground(Color.cyan);
ImageIcon il= new ImageIcon("unzip.jpg");
unzip=new JRadioButton("unzip",il,false);
unzip.setBackground(Color.cyan);
c.add (split);
c.add(zip);
c.add(unzip);
c.add(rename);
// create logical relationship between JRadioButtons
radioGroup = new ButtonGroup();
radioGroup.add(split );
radioGroup.add( zip);
radioGroup.add(rename );
radioGroup.add( unzip);
// setPosition(250,250);
setTitle("FILE UTILITY SOFTWARE");
setSize(300,500);
setVisible(true);
public static void main(String args[])
front33 f=new front33();
f.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e)
System.exit(0);
} -
Hello, I'm pretty new to LifeCycle and don't even know if this is the right program I should be using to do this but I thought I'd give it a shot.
The branch I work for in my company has been doing media planning up in Saskatchewan for about a year now. We build and distribute ads through small towns across Saskatchewan for all types of people. We have been building up a list of newspapers that we can use including the contact information and prices of various sized ads.
We don't have a way to reference all the newspapers quickly. We have to go back through prior folders and find each newspaper and their contact information before we can plan for the next ad run. What I would like to do is build a form that would be easy to just click on a drop down menu, find the newspaper that you want, and then all the information will pop up in a contact box below the drop down menu.
I've already build a mini drop down menu with about 10 newspapers to see if this will work but I don't know how to link the drop down menu item with another box that will open up all the contact and pricing info.
Can someone please help?
Thanks!Hi,
you can do what you want with LiveCycle, and it might help you to look at this reference as it shows how to work with data ( it does depend how your data is stored)
http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000006.htmlhttp://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000006.html
If you data does not change very often then I would recommend just using an XML file to store the data and then use thebinding ability with possible some JavaScript to create the solution you would like.
Hope this helps
Malcolm -
Help with building a database portlet (reference_path) issues
I'm attempting to create a Provider Portlet based on the Database Provider example. The goal of the portlet is to
dynamically display a Portal Report based upon a session storage variable. The session storage variable is set in another portlet on the same page. My portlet is named DYNAMIC_RPT.
I'm able to display the report from within my database portlet by calling the report's .show procedure.
But, my problem is this: The reference_path is generated for my database portlet, for example 131_DYNAMIC_RPT_123123, so when I click the NEXT button on the report, the page is refreshed but the report is still on page 1.
I think the problem is that my portlet needs to internally determine what the reference_path SHOULD BE for the report I'm trying to display, and use it in the associated provider API's.
If I could call the API which is generating the reference_path I could then pass an appropriate reference_path. I would need to be able to dynamically regenerate the reference_path when ever the session variable changes. Is this possible ?
Also, when I'm building the p_arg_names, and p_arg_values whould I ONLY extract the argument(parms) which are associated with the p_reference_path of the portlet report currenttly being displayed ?
Also is there a session storage variable which contains the current PAGE ID and TAB ID. I'm extracting it form the PAGE_URL but it's very messy code.
Thanks in advance for your help !!Hi,
you can do what you want with LiveCycle, and it might help you to look at this reference as it shows how to work with data ( it does depend how your data is stored)
http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000006.htmlhttp://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000006.html
If you data does not change very often then I would recommend just using an XML file to store the data and then use thebinding ability with possible some JavaScript to create the solution you would like.
Hope this helps
Malcolm -
Hi ALl,
Below is a code sample. My question is how to build the query in the for loop of public procedure to call all the private proedures (private_1,private_2,private_3 etc.)
PACKAGE SAMPLE AS
procedure public(start IN integer, end IN integer)
END;
PACKAGE BODY SAMPLE IS
procedure private_1()
BEGIN
END
procedure private_2()
BEGIN
END
procedure private_3()
BEGIN
END
procedure public(start IN integer, end IN integer)
BEGIN
for num in start..end loop
private_ || to_char(num); ?????????????????????????
end loop
END
END;Actually, you can build dynamic PL/SQL and execute it via 'execute immediate':
execute immediate 'begin private_' || to_char(num) || '; end;';But...it will not help in this case because the NDS is executed outside of the scope of the package - it cannot see the private procedures, and it cannot even see public procedures unless you preface the procedure with the package name. -
Help with building AMD64 System
Hi ppl
I need some advice please
I am building an AMD64 system for my friend and want advice from anyone (especially those with 64s already)
The motherboard I will build with is the MSI K8N Platinum nForce3 250 with a 3200+ AMD64
The questions are:
1. What is the best cooler to use:
Thermaltake Silent Boost or Zalman 7000 Al/CU
(I am thinking the silent boost as it is £12 cheaper and the performance is close isnt it. The silent boost is very good on my AMD XP and the Zalman is just as good on my P4)
2. What PSU should I use with the AMD64:
Antec TruePower 480W (similar to mine plus seperate rails) or
Enermax EG465AX-VE(W)FCA Diamond Blue 460W
3. What RAM would be best for this motherboard out of these 3:
(Will performance be hit hard if CAS 2.5 is used otherwise CAS 2 is over budget)
Kingmax PC3500 SuperRAM 433Mhz http://overclock.co.uk/customer/product.php?productid=17006&cat=310
Corsair 1GB DDR Value Select PC3200 Kit http://www.overclockers.co.uk/acatalog/Corsair_Value_Select.html
GeIL 1GB (2x512MB) PC3200 Value Dual Channel Kit CAS2.5
http://www.overclockers.co.uk/acatalog/GeIL_Value.html
Cheers Guys for your help. Could ya answer ASAP
Cheers
SAspazThe Tagan will more than handle a 3200+ and 9800 Pro, are you serious? it will handle anything you can possibly throw at it and not even break a sweat. This PSU is a monster!
Another review: http://www.hexus.net/content/reviews/review.php?dXJsX3Jldmlld19JRD02OTQ=
"The results speak for themselves. Both PSU's were equally able to cope with the testing, each holding close to the target output voltage. The +3.3V and +5V results are the most interesting. The Tagan has discrete supply for each, while the Enermax derives each output voltage from a shared supply. Under load, heavy load on one rail may pull the other rail down too on the Enermax, while theoretically the Tagan should be able to do much better.
The adjusted average figure is derived with peak and trough results removed, stopping them from skewing the results, however it's that peaking of output voltage that can cause a PSU the most problems in supplying clean output. The Tagan, with its return loop, also has an added advantage in high load situations, reducing ripple noise.
While both PSUs seem very competent, indeed I'm proud my long term Enermax did so well, a PSU that takes a newer, refined approach to supplying clean output voltage, like the Tagan, should always win outright.
While it's unscientific at best, the Tagan shines, holding steadfast to the desired voltages on each rail, regardless of load. "
More reviews:
http://www.casemodworld.com/article147.html
"Conclusion
We have all seen power supplies that claim to be 'silent' before. None that I have seen have yet proven to be as good as the Tagan. I had to double check that it was running when I first powered up. The only thing I could hear was the exhaust fan in my case, the PSU was inaudible.
What we like about the Tagan -
* Large Heatsinks
* Excellent Silent Cooling system
* Most silent PSU we have come across
* Lots of molex connectors
* Neater cables due to twisted wires
What we don't like about the Tagan -
* Large mainboard adapter needed
Anyone notice the lack of dislikes? I could only think of one and even that is being picky.
Overall this PSU is simply amazing, the voltages are perfect, is even more silent than I thought and its very reasonably priced. What more could you ask for?"
http://www.themodfathers.jolt.co.uk/?page=&action=show&id=8062
http://modtown.co.uk/mt/review2.php?id=taganpsu -
I need to create first, last, next, and previous buttons in my gui. I have them in there (in the code), but only one button shows up (instead of four), and it has "first" overlapped with the "previous" button. The "next" and "last" don't even show up at all.
Can some one guide me please? Can someone tell me what I am doing wrong?? Thank you in advance
Here is my maker.java which houses the navigation panel
package inventorymain;
import javax.swing.JFrame;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.text.NumberFormat;
import javax.swing.border.*;
import java.net.*;
import java.util.StringTokenizer;
class Maker extends Inventory implements ActionListener
{//begins Class Maker
static String manufact[] = new String[10];
static double restockingFee[] = new double[10];
static int i;
static double TotalVal;
static int navItem;
private Container cp = getContentPane();
GridBagConstraints c;
GridBagConstraints cconstraint;
Border titledborder;
JPanel pan;
String labels[] = {"Product Name:", "Manufacturer:", "Product ID Number:", "Units in Stock:",
"Price Per Unit: $", "Restocking Fee: $", "Value of Product in Stock Plus Restocking Fee: $",
"Value of All Merchandise Plus Restocking Fees: $"};
int len1 = labels.length;
JLabel lbl[] = new JLabel[len1];
JTextField txtfield1[] = new JTextField[len1];
String blabels[] = {"First", "Previous", "Next", "Last"};
int blen = blabels.length;
JButton navigate[] = new JButton[blen];
JLabel lblImg;
File file;
public String FileName;
public Maker(int Item_Number, String Item_Name, double Item_Price, int Items_in_Stock, String manufact, double restockingFee)// Constructor for varibles
super(Item_Number, Item_Name, Item_Price, Items_in_Stock);
this.manufact[i] = manufact;
this.restockingFee[i] = restockingFee;
i = i + 1;
public static void setManufact(int k, String value)
manufact[k] = value;
public static double getRestockFee(int val)
return restockingFee[val];
public void ShowInventory()
setLayout(new FlowLayout());
GridBagLayout contlayout = new GridBagLayout();//layout for container
GridBagConstraints cconstraint = new GridBagConstraints();//constraint for container
GridBagLayout gblayout = new GridBagLayout();//layout for panel
GridBagConstraints gbconstraint = new GridBagConstraints();
try
//first panel
pan = new JPanel();
gblayout = new GridBagLayout();
gbconstraint = new GridBagConstraints();
pan.setLayout(gblayout);
for (int i = 0; i < 2; i++)
for (int j = 0; j < len1; j++)
int x = i;
int y = j;
if (x == 0)
lbl[j] = new JLabel(labels[j]);
lbl[j].setHorizontalAlignment(JLabel.LEFT);
lbl[j].setPreferredSize(new Dimension(250, 15));
gbconstraint.insets = new Insets(10, 0, 0, 0);
gbconstraint.gridx = x;
gbconstraint.gridy = y;
pan.add(lbl[j], gbconstraint);
}//end if
else
txtfield1[j] = new JTextField(15);
txtfield1[j].setPreferredSize(new Dimension(300, 15));
txtfield1[j].setHorizontalAlignment(JLabel.LEFT);
txtfield1[j].setEnabled(false);
lbl[j].setLabelFor(txtfield1[j]);
gbconstraint.gridx = x;
gbconstraint.gridy = y;
pan.add(txtfield1[j], gbconstraint);
}//end else
}//end for
}//end for
Border titledborder = BorderFactory.createTitledBorder("Current Inventory Data");
pan.setBorder(titledborder);
//adds panel to container
cconstraint.gridwidth = 1;
cconstraint.gridheight = 1;
cconstraint.gridx = 0;
cconstraint.gridy = 0;
cp.add(pan, cconstraint);
//add icon to display
pan = new JPanel();
gblayout = new GridBagLayout();
gbconstraint = new GridBagConstraints();
pan.setLayout(gblayout);
gbconstraint.gridwidth = 1;
gbconstraint.gridheight = 1;
gbconstraint.gridy = 0;
lblImg = new JLabel((new ImageIcon(getClass().getResource("logo111.jpg"))));
lblImg.setPreferredSize(new Dimension(120, 60));
pan.add(lblImg);
cconstraint.gridwidth = 1;
cconstraint.gridheight = 1;
cconstraint.gridx = 0;
cconstraint.gridy = 1;
cp.add(pan, cconstraint);
//navigation panel
pan = new JPanel();
gblayout = new GridBagLayout();
gbconstraint = new GridBagConstraints();
pan.setLayout(gblayout);
gbconstraint.gridwidth = 1;
gbconstraint.gridheight = 1;
gbconstraint.gridx = 0;
gbconstraint.gridy = 1;
for (int i = 0; i < blen; i++)
navigate[i] = new JButton(blabels);
gbconstraint.gridx = 1;
pan.add(navigate[i], gbconstraint);
navigate[i].addActionListener(this);
}//end for
titledborder = BorderFactory.createTitledBorder("Navigation");
pan.setBorder(titledborder);
//add panel to container
cconstraint.gridwidth = 4;
cconstraint.gridheight = 1;
cconstraint.gridx = 1;
cconstraint.gridy = 1;
cp.add(pan, cconstraint);
ShowInventory(0);
}//end try
catch (Exception e)
e.printStackTrace();
}//end catch
}//end showInventory
public void ShowInventory(int ItemNo)
txtfield1[0].setText(Integer.toString(ItemNo));
txtfield1[0].setText(Inventory.getItemName(ItemNo));
txtfield1[1].setText(manufact[ItemNo]);
txtfield1[2].setText(Integer.toString(Inventory.getItemNum(ItemNo)));
txtfield1[3].setText(Integer.toString(Inventory.getItemUnits(ItemNo)));
txtfield1[4].setText(Double.toString(Inventory.getItemPrice(ItemNo)));
txtfield1[5].setText(String.format("%3.2f",
Products.totalOfRestockFee(Inventory.getItemPrice(ItemNo),
getRestockFee(ItemNo))));
txtfield1[6].setText(String.format("%3.2f",
Products.totalOfInventory(Inventory.getItemPrice(ItemNo),
Inventory.getItemUnits(ItemNo), getRestockFee(ItemNo))));
txtfield1[7].setText(String.format("%3.2f",
GetTotalInvVal()));
}//end ShowInventory(int ItemNo)
public void EnableFields(boolean bflag)
txtfield1[1].setEnabled(bflag);
txtfield1[2].setEnabled(bflag);
txtfield1[3].setEnabled(bflag);
txtfield1[4].setEnabled(bflag);
txtfield1[5].setEnabled(bflag);
}//end EnableFields
public double GetTotalInvVal()
TotalVal = 0;
for(int j = 0; j < Inventory.getCount(); j++)
TotalVal += Products.totalOfInventory(Inventory.getItemPrice(j),
Inventory.getItemUnits(j), getRestockFee(j));
return TotalVal;
}//end GetTotalInvVal
public void actionPerformed(ActionEvent e)//button actions
String btnClicked = ((JButton)e.getSource()).getText();
if (btnClicked.equals("First"))
EnableFields(false);
navItem = 0;
ShowInventory(navItem);
}//end if
if (btnClicked.equals("Next"))
EnableFields(false);
if (navItem == getCount() - 1)
navItem = 0;
}//end if
else
navItem += 1;
}//end else
ShowInventory(navItem);
}//end if
if (btnClicked.equals("Previous"))
EnableFields(false);
if (navItem == 0)
navItem = getCount() - 1;
}//end if
else
navItem = navItem - 1;
}//end else
ShowInventory(navItem);
}//end if
if (btnClicked.equals("Last"))
EnableFields(false);
navItem = getCount() - 1;
ShowInventory(navItem);
}//end if
}//end ActionPerformed
}// end of class Makerfor (int i = 0; i < blen; i++)
navigate[i] = new JButton(blabels);
gbconstraint.gridx = 1; // ---- > You mean for this be = i, No?
// Somehow you need to be resetting the grid x for each button added
pan.add(navigate[i], gbconstraint);
navigate[i].addActionListener(this);
}//end for
Or check out gridx = GridBagConstraints.RELATIVE
Message was edited by:
nantucket -
Hey,
Just as an experiment, I'm creating a Fake instant messaging application between two computers (one is the host and one is the client). For right now I am having the host read in data from the client, and the host is supposed to display it on its screen. I know the code works, but I am having trouble finding a way to keep the communication line open between the host and the client, without the host 'stalling' and not updating constantly so that it looks like a true application. Here is the code I have:
try
while( true )
String line = input.readLine();
if( line.compareTo("close") == 0 )
break;
else if( line != null )
myGUI.msgTextArea.setText(line);
catch( Exception e )
myGUI.systemLabel.setText("Connection error");
Is there an easy way to update the the GUI without having to stop reading in data from the user? Or do I need to break communication off with the user? Any suggestions? thanks.Use the RMI with the Observer pattern. (The host could fire an event via rmi and the client could listen for the event)
Maybe you are looking for
-
Scheduling in DTW 2004 ??
Hello everyone, Can we do Scheduling in DTW 2004 ? I know that we can scheduling in DTW 2005 but i want scheduling to be done in DTW 2004 or is there any other alternative other than DTW 2004 which can import and update the database ?? If there is an
-
Mapping in XI - cannot access Global Container parameters
Hi all, we have the following problem in graphical XI mapping. Trying to retrieve the run-time value of a global parameter, we cannot access the value itself (e.g. test using "display queue" menu). We use 2 simple user-defined functions (getIdoc and
-
I just purchased and tried using export tool. First I tried uploading a doc through the web interface - I get a file not found error then I tried uploading via my pdf tools interface... It appeared to upload and convert the doc but then an error m
-
Record TV from Cable Box via Firewire
So I have a cable box capable of outputting Tv via Firewire. I have the cable, and using iRecord I can record TV, but it is very cumbersome. I was wondering if anyone could give me a working link to Ical scripts that will launch a AVCVideoCap recordi
-
PHP/MySQL field recognize carriage returns?
I'm a novice PHP/MySQL database driven site builder. I need to have users enter text into a field with carriage returns and have the database recognize and store those carriage returns so it displays when the data is displayed on a PHP page. How do I