|
When posting your question please:- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-fou
|
|
|
|
|
|
Hi, im a uk based java learner. I have bought and downloaded a few beginners books but would prefer a more structured/formal course(preferably online). There are lots of courses out there but im unsure of how good they are and which are better than others. I have limited funds and dont want to waste money on a course that wont teach me what i need to know to progress. Are there any well regarded courses(outside of universities and uk based) that anyone on here have used? I would consider distance learning at a foreign institution. Any advice would be appreciated. Cheers.
|
|
|
|
|
I am trying to get a simple one way Java TLS connection using the bouncycastle provider. For a couple days I have had this issue where on calling the server side SSLSocket.getInputStream() the thread hangs whereas the client side SSLSocket.getOutputStream() method is seemingly successful. In my code I generate a self signed certificate using bouncycastle which is then used in initialising the server side SSLContext with a KeyManager and the client side with a TrustManager. I have tried explicitly starting the handshake with SSLSocket.startHandshake which itself then hangs. Additionally I have spent a good deal of time making my code as similar as possible to the examples given by the BCFips manual and the Java Cryptography: Tools and Techniques book but the problem persists.
This is the security class which has methods to create the V1 certificate, generate RSA keypairs and helper methods for the aforementioned:
private static final String ASYMMETRIC_KEY_ALG = "RSA";
private static final String SYMMETRIC_KEY_ALG = "AES";
private static final String SYMMETRIC_KEY_ALG_MODE_PAD = SYMMETRIC_KEY_ALG + "/ECB/PKCS7Padding";
private static final String PROVIDER = "BC";
private static final String HASH_DIGEST_ALG = "SHA3-512";
private static final String CERT_FACTORY = "X.509";
private static final String KEYSTORE_TYPE = "PKCS12";
private static final String SIGNATURE_ALG = "SHA384with" + ASYMMETRIC_KEY_ALG;
private static final String SECURE_RANDOM_ALG = "SHA1PRNG";
private static final String AUTH_HASH_DIGEST_ALG = "PBKDF2WithHmacSHA512";
// private static final File TRUSTSTORE_NAME = new File("/var/lib/secure-messenger-relay/truststore.p12");
private static final File KEYSTORE_NAME = new File("/var/lib/secure-messenger-relay/keystore.p12");
private static long serialNumberBase = System.currentTimeMillis();
static{
Security.addProvider(new BouncyCastleProvider());
Security.addProvider(new BouncyCastleJsseProvider());
}
// APPARENTLY FUNCTIONALITY TO UPDATE KS PASSWORDS IS GOOD
/**
* Generate an RSA keypair
* @return return the keypair
* @throws GeneralSecurityException
*/
public static KeyPair generateKeyPair()
throws GeneralSecurityException
{
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(ASYMMETRIC_KEY_ALG, PROVIDER);
keyPairGenerator.initialize(new RSAKeyGenParameterSpec(3072, RSAKeyGenParameterSpec.F4));
return keyPairGenerator.generateKeyPair();
}
/**
* Generate a self signed V1 X509Certificate for use by the server to authenticate and sign new users into the network
* it pertains to.
* @param caPrivateKey The private key for use in signing
* @param caPublicKey the public key of the certificate
* @param name The name of the self signing party
* @return The Certificate
* @throws GeneralSecurityException
* @throws OperatorCreationException
*/
public static X509Certificate makeV1Certificate(PrivateKey caPrivateKey, PublicKey caPublicKey, String name)
throws GeneralSecurityException, OperatorCreationException
{
X509v1CertificateBuilder v1CertBldr = new JcaX509v1CertificateBuilder(
new X500Name("CN=" + name),
calculateSerialNumber(),
calculateDate(0),
calculateDate(24 * 365 * 100),
new X500Name("CN=" + name),
caPublicKey);
JcaContentSignerBuilder signerBuilder = new JcaContentSignerBuilder(SIGNATURE_ALG).setProvider(PROVIDER);
return new JcaX509CertificateConverter().setProvider(PROVIDER).getCertificate(v1CertBldr.build(signerBuilder.build(caPrivateKey)));
}
/**
* A date utilitiy for calculating how much time in the future a certificate will be valid for
* @param hoursInFuture the number of hours you want the certificate to be valid for
* @return the Date of that number of hours in the future from the current time
*/
private static Date calculateDate(int hoursInFuture){
long secs = System.currentTimeMillis() / 1000;
return new Date((secs + (hoursInFuture * 60 * 60)) * 1000);
}
/**
* A method for soliciting a distinct serial number for certificate generation for multiple threads
* @return the SerialNumber
*/
private static synchronized BigInteger calculateSerialNumber(){
return BigInteger.valueOf(serialNumberBase++);
}
/**
* produce a salt value for use in password hashing
* @return salt
* @throws NoSuchAlgorithmException missing boi
*/
private static byte[] getSalt()
throws NoSuchAlgorithmException
{
SecureRandom secureRandom = SecureRandom.getInstance(SECURE_RANDOM_ALG);
byte[] salt = new byte[64];
secureRandom.nextBytes(salt);
return salt;
}
}
This is the test class is where I set up the keystore and establish the connection between the server instance SSLServerSocket with accept() and the client SSLSocket instance. The code in the testSession() method is successful in calling the getOutputStream() method:
public class ReceiverClientThreadTest {
// ADD REG AND A SINGLE NETWORK
// ESTABLISH A TLS CONNECTION BETWEEN TWO POINTS WITH
private final static String KEY_MANAGER = "SunX509";
private final static String TLS_VERSION = "TLSv1.2";
// private final static String RNG_ALGORITHM = "DEFAULT";
// private final static String RNG_PROVIDER = "BC";
private static final String PROVIDER = "BC";
private static final String KEYSTORE_TYPE = "PKCS12";
private static KeyStore keyStore1, keyStore2, trustStore2;
private SSLSocket serverSocket;
private SSLSocket clientSocket;
@BeforeClass
public static void setUp() throws GeneralSecurityException, OperatorCreationException, IOException {
// CODE HERE RESPONSIBLE FOR GENERATING V1 CERT AND PUTTING IT IN BOTH KEYSTORE FOR SERVER AND
// TRUSTSTORE FOR CLIENT ( HAVE TRIED WITH AND WITHOUT A PASSWORD FOR setKeyEntry() WITHOUT EFFECT
String name1 = "localhost", name2 = "client";
KeyPair kp1 = SecurityUtilities.generateKeyPair();
X509Certificate cert1 = SecurityUtilities.makeV1Certificate(kp1.getPrivate(), kp1.getPublic(), name1);
keyStore1 = KeyStore.getInstance(KEYSTORE_TYPE, PROVIDER);
trustStore2 = KeyStore.getInstance(KEYSTORE_TYPE, PROVIDER);
keyStore1.load(null, null);
keyStore1.setKeyEntry(name1, kp1.getPrivate(), "relaypass".toCharArray(), new X509Certificate[]{cert1});
trustStore2.load(null, null);
trustStore2.setCertificateEntry(name2, cert1);
// secureSocketManager = new SecureSocketManager(keyStore1, password);
}
@Before
public void init() throws IOException, GeneralSecurityException, InterruptedException, ExecutionException {
// THIS CODE BLOCK CALLS getSSLServerSocket() and getSSLSocketFactory() AND USES THEM WITH TWO CALLABLE THREADS
// TO ESTABLISH A CONNECTION
SSLServerSocket sslServerSocket = getSSLServerSocket();
SSLSocketFactory sslSocketFactory = getSSLSocketFactory();
ExecutorService pool = Executors.newFixedThreadPool(2);
Callable<SSLSocket> c1 = () -> {
return (SSLSocket) sslServerSocket.accept();
};
Callable<SSLSocket> c2 = () -> {
return (SSLSocket) sslSocketFactory.createSocket("localhost", 2048);
};
Future<SSLSocket> server = pool.submit(c1);
Thread.sleep(1000);
Future<SSLSocket> client = pool.submit(c2);
Thread.sleep(1000);
serverSocket = server.get();
clientSocket = client.get();
}
@After
public void tearDown(){
serverSocket = null;
clientSocket = null;
}
@org.junit.Test
public void testSession(){
// SUCCESSFULLY RETURNS FROM getOutputStream()
Thread test = new Thread(new ReceiverClientThread(serverSocket));
test.start();
try (ObjectOutputStream output = new ObjectOutputStream(new BufferedOutputStream(clientSocket.getOutputStream()))) {
System.out.println("here");
}catch (IOException e){
fail();
}
}
private SSLServerSocket getSSLServerSocket() throws GeneralSecurityException, IOException {
char[] entryPassword = "relaypass".toCharArray();
// COULD ADD PROVIDER IN THESE FOR CONSISTENCY
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("PKIX", "BCJSSE");
keyManagerFactory.init(keyStore1, entryPassword);
// specify TLS version e.g. TLSv1.3
SSLContext sslContext = SSLContext.getInstance(TLS_VERSION, "BCJSSE");
sslContext.init(keyManagerFactory.getKeyManagers(),null, null);
SSLServerSocketFactory fact = sslContext.getServerSocketFactory();
return (SSLServerSocket) fact.createServerSocket(2048 );
}
private SSLSocketFactory getSSLSocketFactory() throws GeneralSecurityException{
char[] entryPassword = "relaypass".toCharArray();
// COULD ADD PROVIDER IN THESE FOR CONSISTENCY
// KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KEY_MANAGER, "BCJSSE");
// keyManagerFactory.init(keyStore1, entryPassword);
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("PKIX", "BCJSSE");
trustManagerFactory.init(trustStore2);
// specify TLS version e.g. TLSv1.3
SSLContext sslContext = SSLContext.getInstance(TLS_VERSION, "BCJSSE");
sslContext.init(null,trustManagerFactory.getTrustManagers(), null);
return sslContext.getSocketFactory();
}
}
This thread which is passed the SSLSocket of the client hangs on the call to SSLSocket.getInputStream():
public class ReceiverClientThread implements Runnable {
private final SSLSocket sslSocket;
public ReceiverClientThread(SSLSocket sslSocket) {
this.sslSocket = sslSocket;
}
public void run() {
try (ObjectInputStream input = new ObjectInputStream(new BufferedInputStream(sslSocket.getInputStream()))) {
System.out.println("here");
} catch (IOException e) {
}
}
}
What could I be doing wrong as I have gone through two manuals and done my best to copy the code to the letter. I would suspect foul play in regards to the connection being over localhost but surely the fact that the Callable threads return successfully means that a connection was established and there is an issue with the handshake? Any help would be appreciated. 
|
|
|
|
|
How to integrate the paypal pro version in Java
|
|
|
|
|
Never, ever, accept code from a insecure website to handle anything to do with real money.
You do not know who is giving you the code, you do not know what it does, you do not know that it places the monies correctly into the appropriate account, without passing the details to any third parties.
Only get such code from PayPal themselves - the scope for fraud otherwise is far too large. And remember, you personally could be liable for any monies lost if your action is seen to be negligent - which getting your code from a public forum would most certainly be!
Talk to them: they are pretty friendly and helpful - remember they don't make any money until you are up and running, so it's in their interest to be both!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have a jframe with a jcomboBox and two buttons, the first button allows to add dynamically jcomboBoxes and the second to generate the RDF file.
the elements of comboBoxes are URIs that I extracted from an ontology.
My goal is to generate an RDF file to describe the URIs of the comboBoxes, for example I add 3 comboBoxes to my jframe by clicking on the button "add comboBox" so the final jframe will have 4 comboBoxes, for each combBoxes, I select a different URI and I click on the "generate RDF" button to generate the RDF file, but the problem is that it only works for the first URI and the other three URIs will be identical.
this is my code to add combBoxes :
add.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent e) {
c4 = new JComboBox ();
req1 ();
panel_2.add (c4);
panel_2.revalidate ();
}
this is my code to generate RDF file :
<pre>btnGenerateRdf.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent arg0) {
String u = c2.getSelectedItem (). ToString ();
String uu = c4.getSelectedItem (). ToString ();
Model model = ModelFactory.createDefaultModel ();
String u1 = u.substring (u.lastIndexOf ("#") + 1);
String str = u1.replace ('_', '');
String uu1 = uu.substring (uu.lastIndexOf ("#") + 1);
String str1 = uu1.replace ('_', '');
Resource node = model.createResource (u)
.addProperty (VCARD.N,
model.createResource ()
.addProperty (FOAF.name, str));
Resource node1 = model.createResource (uu)
.addProperty (VCARD.N,
model.createResource ()
.addProperty (FOAF.name, str1));
Resource node11 = model.createResource (uu)
.addProperty (VCARD.N,
model.createResource ()
.addProperty (FOAF.name, str1));
String s = c4.getSelectedItem (). ToString ();
if (add.getActionListeners ()! = null)
{
Resource [] nodes = new Resource [panel_2.getComponentCount () - 2];
for (int i = 0; i <panel_2.getComponentCount () - 2; i ++)
{
String s1 = s.substring (s.lastIndexOf ("#") + 1);
String s2 = s1.replace ('_', '');
nodes [i] = model.createResource (s)
.addProperty (VCARD.N,
model.createResource ()
.addProperty (FOAF.name, s2));
}}
try {
FileOutputStream fout = new FileOutputStream ("C: \\ Users \\ me \\ Desktop \\ file2.xml");
model.write (fout);
} catch (IOException e) {
System.out.println ("Exception caught" + e.getMessage ());
}
}
});
how can i fix this?
|
|
|
|
|
As far as I can see you are using fixed references to access your comboboxes. Create a List(T) for your comboboxes and add each one to the list as you create it. You can then iterate over the list and generate your data for each one as you encounter it in the loop.
|
|
|
|
|
Hi,
I am learning Java and doing some operation related to HashMap. I am trying to add details in hashmap based on city. So suppose below is the list we have :
List<Student> studentList= new LinkedList<>();
studentList.add(new Student(1, "Test1", "US"));
studentList.add(new Student(2, "Test2", "US"));
studentList.add(new Student(3, "Test3", "India"));
studentList.add(new Student(4, "Test4", "Canada"));
studentList.add(new Student(5, "Test5", "Canada"));
studentList.add(new Student(6, "Test6", "India"));
For this I am looking output something like {US=[Test1, Test2], India=[Test3, Test6], Canada=[Test4, Test5]} mainly creating map based on Cities.
I have implemented the code for this but it's time complexity is very high so looking for some optimize solution. Can someone Please help.
private void getDetailsGroupByCity(List<Student> studentList)
{
Map<String,ArrayList<String>> studentHashMap= new HashMap<>();
List<Student> arrayList= new ArrayList<>(studentList);
List<String> names= new ArrayList<>();
Set<String> setKey= new HashSet<>();
for (Student student : arrayList) {
setKey.add(student.getCity());
}
for (String s : setKey) {
for (Student student : arrayList) {
if (s==student.getCity())
{
names.add(student.getName());
studentHashMap.put(s, (ArrayList<String>) names);
}
}
names= new ArrayList<>();
}
System.out.println(studentHashMap);
}
Thanks for your help in advance Happy Learning for me 
|
|
|
|
|
You could use the SortedSet (Java Platform SE 7 )[^] which allows you to provide your own sort comparator. This means you can easily extract all the entries for each country (maybe keeping a separate List<E> of the countries.
|
|
|
|
|
I get a "javax.net.ssl.SSLHandshakeException: certificate expired" error which supposedly means the distant end has an expired certificate.
The reality is that the distant end doesn't have a certificate at all. Does that show up as an "expired" cert?
Is there a way around it? (I'm not really a java person or, in this case, groovy.)
|
|
|
|
|
I'm looking for a good open source Gantt chart library for Java Swing. I tried JFreeChart but it is not able to draw subtask. I tried with SwiftGantt too. It is able to draw subtask, but it is a little unstable and the look and feel is not professional :(.
Can you recomends others?
Thanks in advance!
|
|
|
|
|
Sorry if this is an offtopic in this group.
I want to buy a laptop for Java development. Of course the question would be simple if I were doing just plain Java development. But I want to try new technologies often used with Java - Kubernetes, Docker etc. That's why I'm asking it here.
These technologies (K8s, Docker) use virtualization. I know that you need to set something in BIOS/UEFI to run Docker. Some years ago I had to buy a new CPU to run 64-bit virtual machines, because my previous CPU was not supporting 64-bit guest virtual machines. The feature in question was called VT-x.
Of course the sure thing would be to buy a Mac, but I want a 500-600 EUR laptop.
So the question is:
1) Do I need to search for some show-stopper CPU features when choosing a computer?
2) Anything that does not work on AMD chips?
3) Is 8GB RAM sufficient for small/medium sized personal projects?
4) Any other pitfalls?
5) Is Windows 10 Home somehow unusable for professional software development?
|
|
|
|
|
8GB would be fine for dev work, but testing may be pushing it. You're very likely going to be limited to running one virtual machine along side your other dev stuff.
Get the fastest processor you can for the money and make sure you get a machine running on an SSD, preferably 1TB.
The only other thing I'm going to tell you is stay away from Windows Home. It will not support virtualization.
|
|
|
|
|
I will answer your questions on by one.
1. If you go for a medium-range Intel i5 or i7 CPU, you are getting a quite versatile CPU which will satisfy all your needs. If your workload includes hardcore video editing and image processing, then you will be better off with the AMD. Otherwise, nothing beats Intel.
2. For CPU chips, in terms of processing, AMD lags behind Intel in every aspect except for video editing. While AMD GPUs are better for graphic creation, you need NVIDIA GPUs to run CUDA.
3. Judging by the workloads that even web browsers are putting on RAMs nowadays, you should go for 16 GB RAM minimum.
4. While the MacBook is the first choice for many, you will enjoy the playfulness of a Windows laptop.
5. Installing frameworks can be tedious on Windows but nothing worth complaining once you get used to it. One huge benefit of a Windows machine is that you can create a Dual boot with Linux or install Linux in a Virtual Machine software. Then you can use both and choose your favorite.
|
|
|
|
|
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
public class Workers extends javax.swing.JFrame {
Connection con;
Statement stmt;
ResultSet rs;
/**
* Creates new form Workers
*/
public Workers() {
initComponents();
DoConnect();
}
public void DoConnect(){
try{
String host="jdbc:derby://localhost:1527/Employee";
String uname= "Star";
String uPass ="ST@r6738";
Connection con=DriverManager.getConnection(host, uname, uPass);
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String SQL="SELECT * FROM WORKER";
ResultSet rs=stmt.executeQuery(SQL);
rs.next();
int id_col =rs.getInt(1);
String ID_=Integer.toString(id_col);
String first_name=rs.getString("FIRST_NAME");
String last_name=rs.getString("LAST_NAME");
String job_title=rs.getString(4);
textID.setText(ID_);
textFirstname.setText(first_name);
textLastName.setText(last_name);
textJobTitle.setText(job_title);
}
catch(SQLException err){
System.out.println(err.getMessage());
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
textFirstname = new javax.swing.JTextField();
textID = new javax.swing.JTextField();
textLastName = new javax.swing.JTextField();
textJobTitle = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
btnFirst = new javax.swing.JButton();
btnPrevious = new javax.swing.JButton();
btnNext = new javax.swing.JButton();
btnLast = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
textID.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
textIDActionPerformed(evt);
}
});
jLabel1.setText("JOB Title");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(textID, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(textFirstname, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(textLastName, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(3, 3, 3))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(textJobTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(textID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(textFirstname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(textLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(textJobTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(41, 41, 41))
);
btnFirst.setText("First");
btnPrevious.setText("Previous");
btnPrevious.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPreviousActionPerformed(evt);
}
});
btnNext.setText("Next");
btnNext.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnNextActionPerformed(evt);
}
});
btnLast.setText("Last");
btnLast.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLastActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(btnFirst)
.addGap(18, 18, 18)
.addComponent(btnPrevious)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnNext)
.addGap(18, 18, 18)
.addComponent(btnLast)
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnFirst)
.addComponent(btnPrevious)
.addComponent(btnNext)
.addComponent(btnLast))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(21, 21, 21))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(602, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void textIDActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {
try{
if (rs.next()){
int id_col =rs.getInt("ID");
String id=Integer.toString(id_col);
String first_name=rs.getString("FIRST_NAME");
String last_name=rs.getString("LAST_NAME");
String job_title=rs.getString(4);
textID.setText(id);
textFirstname.setText(first_name);
textLastName.setText(last_name);
textJobTitle.setText(job_title);
}
else{
rs.previous();
JOptionPane.showMessageDialog(Workers.this, "End of file");
}
}
catch(SQLException err){
JOptionPane.showMessageDialog(this, err.getMessage());
err.printStackTrace();
}
}
private void btnPreviousActionPerformed(java.awt.event.ActionEvent evt) {
}
private void btnLastActionPerformed(java.awt.event.ActionEvent evt) {
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Workers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Workers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Workers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Workers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Workers().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnFirst;
private javax.swing.JButton btnLast;
private javax.swing.JButton btnNext;
private javax.swing.JButton btnPrevious;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JTextField textFirstname;
private javax.swing.JTextField textID;
private javax.swing.JTextField textJobTitle;
private javax.swing.JTextField textLastName;
// End of variables declaration
}
|
|
|
|
|
You need to use your debugger to step through the code in that method to find out which reference is null. It is not something that anyone here can do for you.
|
|
|
|
|
Message Closed
modified 25-May-20 13:01pm.
|
|
|
|
|
|
But then he wouldn't be able to push his spam link to his article writing service.
NB: The person you're replying to isn't the OP.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
We have been given a project for my ComSci class and I've done what i think is half, but got feedback today and it was devastating. I dont know what to do. The final hand in is on the 1st of June. Is there anyone willing to maybe help me write the code? The most complex coding knowledge needed is 2D arrays. I would really appreciate it
|
|
|
|
|
Sorry, this site does not provide code to order. For a start it does not help you to hand in work written by someone else. If you cannot understand your assignment then you need to go over your study and course notes a few more times. There is also lots of useful information and sample code at The Java™ Tutorials[^]
|
|
|
|
|
Hi, first time posting so hopefully doing it correctly. I have used a form builder to build my forms but have run into a couple of issues with functionality. In the code/calculation below I need to be able to return the answer 0 if the answer is less than 0. I've searched loads to no avail so any help would be much appreciated. T.I.A.
$('form#Commission #Commission_On').formCalc(" Nett_Earnings -Actual_Takings >0==0",{ currency_format:true, mirror:'sfm_Commission_On_parsed'});
modified 17-May-20 10:15am.
|
|
|
|
|
What language is that, it does not look much like Java? However assuming it is supposed to convert that string into an actual sum it does not look valid. In the expression Nett_Earnings -Actual_Takings >0==0, what is >0==0 supposed to mean?
|
|
|
|
|