Uploaded attachment:
Works just fine from here. (Firefox 3.0.10)
Uploaded attachment:
Works just fine from here. (Firefox 3.0.10)
You would want the clause to be m=$todaysMonth AND d=$todaysDay AND y=$todaysYear
Why not set the parameters of your query to only pull records where m=$todaysMonth and d=$todaysDay and y=$todaysYear?
Yes, that should be the case. If you're using netbeans to debug it, set a break point on the switch statement.
One note on your switch though. If you want to it to perform like the series of if() statements you had earlier, you need to remove the break statements and let the cases fall through so they are additive.
Are you certain that you have added the listeners to the jComboBox1 control? You would need to post the full code to track it down further.
Any suggestions as to why its saying I can't set it up with my .getSelectedIndex() ?
The only problems I really saw with the if() block code you posted up above was the lack of parenthesis for the "getSelectedIndex" method calls and the condition statement on the else portion, which I mentioned previously. If neither of those are the problem, you'll need to post the exact error message and stack trace.
As for an array of text fields, all in all it would still be just about as many lines of code but it would look cleaner to do it that way.
Well, I would say this is a few less lines
for (int i=0; i<jComboBox1.getSelectedIndex(); i++) {
textFields[i].setVisible(true);
}
A fall-through switch is more hard-coding than I would prefer, but still far fewer than that if-else block (which could really be just a series of if() statements to eliminate the repetitive statements.)
switch (jComboBox1.getSelectedIndex()){
case 2:
cTextField.setVisible(true);
// fall through
case 1:
bTextField.setVisible(true);
// fall through
case 0:
aTextField.setVisible(true);
}
There is no condition on an "else" clause, so this isn't valid syntax
else (jComboBox1.getSelectedIndex == 9)
.
The bigger question is why not use a switch or even better yet, an array of text fields so you don't have so much manually repetitive code.
There is a rather lengthy discussion about fixing this here if you need to try a few other things. A co-worker of mine had the same problem recently with an older laptop he picked up and he fixed it by actually clipping the wire to the thing, but you might not want to go that far just yet :)
You may need to download the drivers from Dell or Synaptics if you have installed software for the newer mouse.
Edit: This driver is another possibility: http://support.dell.com/support/downloads/download.aspx?c=us&l=en&s=gen&releaseid=R86229&SystemID=INS_PNT_P4_8200&servicetag=&os=WW1&osl=en&deviceid=2514&devlib=0&typecnt=0&vercnt=7&catid=-1&impid=-1&formatcnt=1&libid=17&fileid=112896
Try disabling the "Pointing Stick" (the little mouse nubby thing that's in the middle of the keyboard) in the mouse section of your control panel.
Using the build in tools for it doesn't look too tricky: http://www.eclipse-blog.org/eclipse-ide/generating-javadoc-in-eclipse-ide.html
If there are specific parts you don't understand, post a more detailed explanation of what you're hung up on.
The Mathematics of the 3D Rotation Matrix might be worth a read for you. If it's too deep at the moment, perhaps it will be helpful as you get in further.
Gamedev has many articles on matrices as well if you want to peruse them: http://www.gamedev.net/reference/list.asp?categoryid=28#259
Looks like it would probably be pretty handy, but it will still require some study and understanding of the api. They do have some examples here: http://wiki.modularity.net.au/ical4j/index.php?title=Examples#Creating_a_new_calendar that might help.
To the OP, it still just comes down to translating your own calendar object entries to a standard documented text interchange format. You have properties that you must write as entries into a text file in based upon that specification. To import, you have to read those entries and put the info into your own objects.
vCal spec can be found here: http://www.imc.org/pdi/pdiproddev.html
I found plenty more info on iCal with a simple Google search. Have you looked at any of that?
Yes, sorry, I guess I wasn't very clear. I had a scenario like what Vernon mentions above in mind when I said that the component starts with a cleared background. I was assuming a call to super.paintComponent() before any other painting.
Regarding the rep comment about it possibly being the Collection.sort() call, no it is not, read the API docs - NoSuchElementException is not thrown by that method.
Sorting an empty collection is actually the easiest operation you could hope to implement :P
If you consider that the component generally starts with a cleared surface of the background color, it's often unnecessary to use clearRect() or fillRect() to clear out the background, but if you are maintaining an image reference for purposes of buffering some updates then you would need to clear that manually before painting the new data.
Distance to center would provide a single calculation to check against that only involves two points. It's arbitrary, really, how close you decide is "close enough" for the association for "A vs B". Given that you only have to know when a user a dragged them near one another, I wouldn't bother determining min distance checks per side.
In the same vein you are already discussing, keep in mind that you don't have to code all of the coordinate stuff yourself either. You can make a small wrapper to manage that glyph that just contains the other objects you need to work with
class TeamGlyph {
private Team team;
private Rectangle2D glyph;
// etc
}
and you can forward to any of those methods as needed.
Form1 form = new Form1();
form.setVisible(true);
Of course, that still leaves it to you to create your "Form1" class that extends JFrame or whatever.
http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html
i need more precise info like; go grab this brand this model and this guitar, then you are good to go...
It's just not that simple. There is a wide variety of amps with a wide variety of different sounds and settings. Add in effect pedals/boards such as those that Mosaic mentioned above and the subtleties of effect become quite numerous and it's not uncommon for different effects/settings to be used at certain points in a particular piece of music. That said, you can often get fairly close with the settings available on many reasonably priced amplifiers and perhaps a pedal or two (chorus is nice sometimes).
You didn't say which line the error is occurring on, but I am guessing that it's this one
int minMarks = Collections.min(tmaMarks);
because the Collections.min() method states that exception is thrown when it's invoked on an empty collection - which you are doing.
Looks reasonable, however you probably want to sleep for a bit between each update and you may want to ensure that your updates to the text area are being made on the event thread
public void run() {
try {
setFinish(false);
for (int i = 0; i < 1000; i++) {
// queue the text update
SwingUtilities.invokeLater(new Runnable() {
public void run() {
myTextArea.setText(myTextArea.getText() + i);
}
});
// sleep for a bit so repaint and other stuff can process
Thread.sleep(100);
}
setFinish(true);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
You would need to run a loop like that on a separate thread from the Event Dispatch thread because that event thread is where repaints of the screen are processed. There is a small tutorial on that here: http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html
As you have it described, simply java Main
should work just fine. You do not need to include the ".class" part. In fact, when the "java" command sees the ".", it assumes that is a package designation, which is why it is trying to find "Main/class".
So from my understanding, the getTableCellEditorComponent method is what gets called when the user clicks on a cell of the JTable, and inside that method, you are updating the JComboBox by removing everything from it and then adding all the elements from the Vegetarian column to it?
Mostly correct, yes. I'm removing the elements from the ComboBoxModel and adding the contents of a List of entries that is mapped to the value of the Vegetarian column. So the Map contains one List for the value "true" and another for the value "false".
You could just as easily store two(or more) separate models in the map and not even bother with the clear/add part - just pull the model from the map and use setModel() to swap it directly.
Well, perhaps this chapter from Thinking In Java, 3rd ed will be helpful: http://www.codeguru.com/java/tij/tij0087.shtml
You might look through the info on Java Glossary as well: http://mindprod.com/jgloss/array.html
Yes, dumping your homework into 4 posts with no code tags and no specific questions is not likely to yield a lot of constructive advice.
What is drives the change in the combo box entries? You can change the values in the combo box model pretty easily as needed. Here is an example that updates the values in the combo based upon the value in another table column (the "Vegetarian" column in this case). The bulk of the code is Sun's TableRenderDemo code (hence the big copyright notice, sorry, I just wanted a chunk of table model code I could edit real quick for an example). I added the "ComboEditor" class and used that in place of the DefaultCellEditor. Relevant changes in bold:
/*
* Copyright (c) 1995 - 2008 Sun Microsystems, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Sun Microsystems nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, …
I do not understand the way in which an array of type string can be associated with int values and double values in order for calculations, and therefore displays, to be credited correctly. Any help or insight would be greatly appreciated.
I'm not certain that I understand your question exactly, but it kind of sounds like you're wanting a HashMap (which is a implementation of the more generic Map collection interface). HashMap allows you to associate an Object key to an Object value: key->value.
Try this instead
function checkValues($postValues)
{
$valid = true;
foreach($postValues as $key => $value)
{
if(!isset($key) || $value == "")
{
$valid = false;
}
}
return $valid;
}
Edit: Noticed that the && should be ||
I think you're probably having a resource location issue. Take a look through this info on loading images with getResource():http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html#getresource
I'mo going to come clean here: I don't think that separation of the controller and the view works well in a typical Swing app, and I personally rarely do it. The controller needs so much access to the fields in the view that the code is far simpler when they are in the same class.
I agree. It's pretty much just model and view in most cases.
Yes, thanks James, that's a good point to mention on the asynchronous update. It definitely adds some concurrency concerns which need to be weighed against any perceived performance gains.
I should probably clarify that I didn't link the article in a sense of "here's an even better way to do it" so much as here's another example that goes even further - and it has diagrams! :)
You are very close there: int[][] apostas = new int[n][7];
You want 'n' elements that each contain an array of 7 elements. Your outer loop for(int i=0;i<n;i++)
then denotes that first dimension, so aposta[i]=geraAposta();
You may want to glance through this article as well, which shows a simple pattern of even further separating the observers from the observed with a message queue on a separate thread: http://www.javaworld.com/javaworld/javatips/jw-javatip29.html
It's probably overkill for what you have in mind, but it does present another example of separating the state of one thing from other things that may want to observe and react to that state.
(And it has pictures, which my plain example does not :P )
Here's the simplest example I can piece together of a listener (which is an observer). You've used it quite a bit in Swing and I'm sure you will recognize the elements immediately
import java.util.ArrayList;
import java.util.List;
public class mainTest {
public static void main(String[] args) {
Model model = new Model();
View view = new View();
/** add the view as a listener */
model.addListener(view);
/** do something to the model */
model.updateSomething();
}
}
class Model {
/** list of interested listeners (observers, same thing) */
List<ModelListener> listeners = new ArrayList<ModelListener>();
/** add a new ModelListener observer for this Model */
public void addListener(ModelListener listener) {
listeners.add(listener);
}
/** called internally when you need to tell the observer stuff changed */
private void fireStuffChanged() {
for (ModelListener listener : listeners) {
listener.stuffChanged();
}
}
/** method that results in a change in the model */
public void updateSomething() {
// do whatever
System.out.println("Model: I'm changin stuff in here...");
// notify observers
fireStuffChanged();
}
}
/** interface for the listeners/observers callback method */
interface ModelListener {
void stuffChanged();
}
class View implements ModelListener {
public void stuffChanged() {
System.out.println("View: Oh, something changed. I better show the new stuff!");
}
}
It did take a little fiddling around with it before suspecting the AWT Label thing. The behavior was just odd enough to suspect some mixing of AWT and Swing components and sure enough he was using Label. The missing "J" certainly didn't just jump right out of all that code :)
Ok, I had a few minutes to play with the code. The main problem is that you are using java.awt.Label instead of javax.swing.JLabel for the labels in AddRecord. It' not a good idea to mix heavyweight AWT components with Swing components in the same UI. That was causing the problems with painting your menu properly.
Here's some revised code that behaves properly. Note that I put some of the separate classes inside "TheFrame" as inner classes just for my own convenience. You can certainly move them back out.
////// main , the frame ///////
import java.text.MessageFormat;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
public class TheFrame extends JFrame
{
private JPanel menuPanel;
private JPanel text;
private BorderLayout bl = new BorderLayout();
public TheFrame()
{
JLabel one = new JLabel("Java Final Project: Employee Record");
one.setAlignmentX(0.5f);
one.setAlignmentY(1f);
JLabel two = new JLabel("Written by Henry Li");
two.setAlignmentX(0.5f);
two.setAlignmentY(1f);
text = new JPanel();
text.setBackground(java.awt.Color.white);
LayoutManager boxLayout = new BoxLayout(text, BoxLayout.Y_AXIS);
text.setLayout(boxLayout);
text.add(one);
text.add(two);
// add the menu
createMenu();
// set close op also
setDefaultCloseOperation(EXIT_ON_CLOSE);
// don't need
// add(menuPanel, BorderLayout.NORTH);
getContentPane().add(text, BorderLayout.CENTER);
validate();
setBounds(400, 400, 600, 300);
setVisible(true);
}
// Moved everything from menu panel here
private void createMenu(){
JMenuBar menuBar;
JMenu menuFile, menuEdit;
JMenuItem closeMenuItem, printMenuItem, showTableMItem, addRecordMItem;
menuFile = new JMenu("File"); // menu file
menuFile.setForeground(java.awt.Color.black);
closeMenuItem = new JMenuItem("Close"); // menu closeItem
menuFile.add(closeMenuItem); // menu file with closeItem
closeMenuItem.setAccelerator(KeyStroke.getKeyStroke('q', java.awt.Event.CTRL_MASK, false));
closeMenuItem.addActionListener(new closeMenuHandler());
printMenuItem = new JMenuItem("Print"); // menu printItem
menuFile.add(printMenuItem); // menu file with printItem
printMenuItem.setAccelerator(KeyStroke.getKeyStroke('p', …
You can disagree with the rule all that you like - it's still a rule that you must adhere in your postings.
I just quickly glanced through the code, so perhaps I missed something, but it looks like you've added a JMenuBar to a JPanel and added that to your JFrame. I would recommend using setJMenuBar() method on JFrame to add the menu to the frame.
You're trying to access element 43 of a vector that only contains 2 elements.
Also, this code opVect.removeElementAt(opVect.lastElement());
is using an object parameter, lastElement(), instead of an int index parameter for removeElementAt(). You are doing that in several places and really the only reason it even compiles is a nuance of auto-boxing and upcasting of char. You need to supply an index parameter for those calls or use remove(Object) instead of removeElementAt(int).
It's also promotion of your own software, which is against the rules of the forums.
If you're using 5.0, then do you have a version of that class named "Vector" (in caps, not lower case) in that directory? Because, as James mentioned, you may have namespace collision problems.
This call opndVect.get(opndVect.lastElement());
isn't valid because lastElement() returns an Object and get() requires an int index parameter. lastElement() itself returns the last element in that Vector, so really the get() is redundant anyway.
Are you compiling against java 1.5 or later? Those declarations of Vector are perfectly valid post-1.5. You have other issues with using get(Object) calls that are not valid, but the declarations are fine.
Why not mark it solved yourself? The link is right there at the bottom of the thread :)
It's ok. I'll clean out the first two. I didn't want to delete them if there actually was a slight edit in the code that you intended.
Is there any difference in those or did you post three copies of the exact same thing?