/r/javahelp
General subreddit for helping with Java code.
General subreddit for helping with Java code.
Message the mods if you have suggestions.
Java Discord server (unofficial)
Learning Java
Please head over to /r/learnjava and read the sidebar there.
The best free Java tutorials are:
Use the MOOC as main course and Java for Complete Beginners as secondary resource.
Don't forget the Official Oracle Java Tutorials and the Official Java Documentation as they are extremely valuable resources.
Where should I download Java?
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free.
If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others:
Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
Posting rules
DO NOT DELETE your posts once they are solved!
No illegal/pirated content!
No "Do my homework" posts!
Describe the problem and what you want to achieve.
Do not ask for or reply with solutions or keys to solutions.
Use the search function.
No offers/requests to/for help via PM, Discord, Skype, etc.
Post titles must be descriptive.
No promises of rewards of any kind!
Don't be a Jerk!
No JavaScript, Android, Minecraft or Processing!
No links to your stackoverflow questions.
Format your code.
No screenshots of code!
No AI generated content!
/r/javahelp
Generally a new beginner to Java. I am in a programming course that makes a game and it uses inteliji community edition to programs. I want to program for fun on the side and publish projects, but the thing is, I don't know when to use a certain statement or stuff like that. For example, using for loops to loop through an array list, or when to call a public variable, how to debug, how to make the game successfully work
Hello everyone! Just to clarify, I'm NOT asking for help with homework, I'm asking for help with a concept. I was getting the hang of nested loops but its so frustrating to learn it on my own. I'm trying to create a loop for "tina" the turtle but I'm at a point where I don't know how to fix my code.
I'm trying to make the turtle go into a triangle loop, it goes forward, left (at an angle), and then another left at an angle.
Here is what I have so far:
I know that something it wrong but I can't put my finger on it. I would appreciate any leading question or concept explanations that can help me to fix it on my own. Thank you everyone!
Turtle tina = new Turtle(0,100);
tina.penColor("black");
tina.speed(116);
for(int i=0; i<180; i++); {
tina.forward(120);
tina.left(120);
tina.left(120);
}
I spent some time with Elixir and Phoenix LiveView is adorable. Not having to deal with Javascript to build the frontend is so good. I'm wondering if anything like this exists for Java.
I'm a senior developer. I saw Java during school but since then I've moved on and programmed in other languages like Ruby, Javascript, C#, and many many years in Go. Now I need to go back to Java. My main use case are micro services. There is any good book that covers modern Java development?
Hi guys. So it's been a while since I used eclipse. Previously the context menu used to be large enough to fit all the options, but now it's minimized itself when I installed the new version and I need to cycle through the options using arrow keys or the up down buttons shown in the window. Can anyone help me fix this problem? I want to see all the options and click them instead of having to cycle through half the menu options to find the right one. It's driving me mad. Specifically I mean the menu that appears when you right click something in eclipse.
import java.util.Scanner;
class FibonacciThread extends Thread { private int[] fibonacciSequence; private int numberOfElements;
FibonacciThread(int n) {
numberOfElements = n;
fibonacciSequence = new int[n];
}
@Override
public void run() {
int fib1 = 0, fib2 = 1;
fibonacciSequence[0] = fib1;
fibonacciSequence[1] = fib2;
synchronized (this) {
System.out.println("Fibonacci Thread processing to generate Series of " + numberOfElements
+ " Elements...");
for (int i = 2; i < numberOfElements; i++) {
try {
int fib3 = fib1 + fib2;
fibonacciSequence[i] = fib3;
fib1 = fib2;
fib2 = fib3;
System.out.print(".");
} catch (Exception ie) {
System.out.println(ie);
}
}
System.out.println("\nFibonacci Thread has completed generating the series.");
notify(); }
}
public int[] getFibonacciSequence() {
return fibonacciSequence;
}
}
class AnotherThread extends Thread { private FibonacciThread fibonacciThread;
AnotherThread(FibonacciThread fibonacciThread) {
this.fibonacciThread = fibonacciThread;
}
@Override
public void run() {
int a=70;
synchronized (fibonacciThread) {
System.out.println("Another Thread acquiring lock on Fibonacci Thread...");
try {
fibonacciThread.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
a=a*7;
System.out.println("Another Thread released lock on Fibonacci Thread."+a);
}
}
}
class Input {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of Fibonacci numbers to generate: ");
int numberOfElements = scanner.nextInt();
FibonacciThread fibonacciThread = new FibonacciThread(numberOfElements);
AnotherThread anotherThread = new AnotherThread(fibonacciThread);
synchronized (fibonacciThread) {
fibonacciThread.start();
anotherThread.start();
try {
System.out.println("Parent Thread Waiting for Fibonacci Thread to generate all Fibonacci Numbers...");
fibonacciThread.wait();
System.out.println("Fibonacci Thread has been Notified to Parent Class: Series has been generated Successfully.");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Fibonacci Thread has been Notified to Parent Class: Series has been generated Successfully.");
System.out.println("Main Thread (Parent Thread) Printing the Fibonacci Elements from Array...");
int[] fibonacciSequence = fibonacciThread.getFibonacciSequence();
for (int i : fibonacciSequence) {
System.out.print(i + "\t");
}
System.out.println("\nParent Thread (Main Thread) has completed its Process.");
}
}
}
Output:
Enter the number of Fibonacci numbers to generate: 16
Parent Thread Waiting for Fibonacci Thread to generate all Fibonacci Numbers... Another Thread acquiring lock on Fibonacci Thread... Fibonacci Thread processing to generate Series of 16 Elements... .............. Fibonacci Thread has completed generating the series. Fibonacci Thread has been Notified to Parent Class: Series has been generated Successfully. Fibonacci Thread has been Notified to Parent Class: Series has been generated Successfully. Main Thread (Parent Thread) Printing the Fibonacci Elements from Array... 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Parent Thread (Main Thread) has completed its Process. Another Thread released lock on Fibonacci Thread.490
As per most sources notify only "notifies" one thread,but the output says otherwise(for most of the time,when 'Anotherthread' manages to lock FibonacciThread).
Also why do we use synchronized (this) in the FibonacciThread class.
I actually modified the code that was available on a site to see if a thread can acquire lock between the wait-notify period.
I am uisng a SOAP API that returns some customer data. I need to create a java client application to call this SOAP API. I was able to invoke this using Soap ui for the purpose of testing. Now I want to invoke this programatically using Java.
When connecting to the API using Soap UI below steps are followed:
- Added a key store providing a certificate in .pfx format and a password.
- Created outgoing WS security configurations with following configurations
- Timestamp with 30000 as the Time to live value and set the precision of timestamp to miliseconds.
- Signature configurations:
- Keystore: added keystore in the above step.
- Alias: 1
- password: *****
- Key Identifier type: Binary Security Token
- Signature Algorithm: default
- Signature Canonicalization: default
- Digest Algorithm: default
- prepended the sgnature element to the security header
- parts:
Name | Namespace | |
---|---|---|
Timestamp | http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd | content |
Body | http://schemas.xmlsoap.org/soap/envelope/ | content |
To | http://www.w3.org/2005/08/addressing | content |
MessageID | http://www.w3.org/2005/08/addressing | content |
Action | http://www.w3.org/2005/08/addressing | content |
- Created Basic Auth with above outgoing signing configuration.
- WS-A configuration:
- Enable WS-A addressing
- Must understand: NONE
- ws-a version: 200508
- Action: action url
- MessageID: randomly generated message id
- To: to url
I tried to simulate the same in Java (using the Apache CXF library), but ran into some issues. I need guidance to create a Java client to connect with this endpoint. Could someone please assist?
I am trying to figure out why this code below creates an error but things like Object o = list.get(0); System.out.print(o); doesnt and prints the list normal. In what examples should I cast and what examples do things work like normal. If anyone could explain how object type works in these cases that would be great
List<Object> list = new
LinkedList<Object>();
Queue<Double> li = new
LinkedList<Double>();
li.add(3.14);li.add(2.71);
list.add(li);
Queue<Double> ll = list.get(2);
System.out.println(ll.remove());
Hello everyone. I'm starting to learn Java and I would love to know what books would you suggest to quickly learn the features of the Spring boot framework and how to use it in a microservice architecture.
I come from an ASP.NET Core background and have solid experience there. Now, I'm exploring Java's ecosystem, especially when it comes to building APIs. I'm interested in resources that would help me quickly get up to speed and I would love to hear what books or resources would you recommend.
How can I make a sin wave to audio in java in the format y(t) = A sin(2πft).
Here's my code:
(Line 15)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main {
public static void main(String[] args){
Player obj = new Player(0, 0);
window(obj);
}
static void window(Player obj){
JFrame window = new JFrame();
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setTitle("UserInterface2D");
window.setMaximumSize(new Dimension(962, 644));
window.setMinimumSize(new Dimension(481, 332));
window.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(3, 3, 3, 3);
JLabel coords = new JLabel("X: "+ obj.x+"\nY: "+ obj.y);
JButton up = new JButton("Up");
up.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
obj.y += 1;
coords.setText("X: "+ obj.x+" Y: "+ obj.y);
}
});
JButton down = new JButton("Down");
down.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
obj.y -= 1;
coords.setText("X: "+ obj.x+" Y: "+ obj.y);
}
});
JButton right = new JButton("Right");
right.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
obj.x += 1;
coords.setText("X: "+ obj.x+" Y: "+ obj.y);
}
});
JButton left = new JButton("Left");
left.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
obj.x -= 1;
coords.setText("X: "+ obj.x+" Y: "+ obj.y);
}
});
c.gridy = 0;
c.gridx = 1;
up.setPreferredSize(new Dimension(70, 70));
window.add(up, c);
c.gridy = 2;
c.gridx = 1;
down.setPreferredSize(new Dimension(70, 70));
window.add(down, c);
c.gridy = 1;
c.gridx = 0;
left.setPreferredSize(new Dimension(70, 70));
window.add(left, c);
c.gridy = 1;
c.gridx = 2;
right.setPreferredSize(new Dimension(70, 70));
window.add(right, c);
c.gridy = 0;
c.gridx = 4;
c.gridheight = 3;
coords.setFont(new Font("Roboto", Font.PLAIN, 32));
window.add(coords, c);
}
}
class Player {
int x, y;
public Player(int x, int y) {
this.x = x;
this.y = y;
}
}
I have a problem with my Java Sring app. I have added the Model Mapper dependency, but Java couldn't detect the class to import it into the project. This is the code and the pom.xml:
package com.t3c.aretnz.service;
import com.t3c.aretnz.dto.MessageDto;
import com.t3c.aretnz.exception.NotFoundException;
import com.t3c.aretnz.model.Message;
import com.t3c.aretnz.repository.MessageRepo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.modelmapper.ModelMapper;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.UUID;
u/Service
u/RequiredArgsConstructor
public class HelloService {
u/Autowired
private final MessageRepo repo;
private final ModelMapper mapper;
public Message callMessage(UUID id) {
// return new Message(Data.from(Instant.now()), "Hello");
// return Message.builder().timestamp(Date.from(Instant.now())).message(message).build();
//
// return repo.getMessages().stream()
// .filter(m -> m.getId().equals(id))
// .findFirst()
// .orElseThrow(NoSuchElementException::new);
return repo.findById(id).orElseThrow(() -> new NotFoundException(id.toString()));
}
public List<Message> callAllMessages(){
return repo.findAll();
}
public Message createMessage(MessageDto dto){
Message toSave = Message.builder()
.timestamp(Date.from(Instant.now()))
.message(dto.getMessage())
.build();
return repo.save(toSave);
}
}
And the pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.t3c</groupId>
<artifactId>aretnz</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>aretnz</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-security</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.modelmapper/modelmapper -->
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.4.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Hello everyone,
i'm now building DTO classes and I'm facing a problem i can't solve.
I searched in google and asked chatGPT but I couldnt find any usefull help for my case...
Basicaly I have this DTO class above...
The problem is that the "replies" atributte can be an empty string ("") or an object... My goal is to set the right DTO class when "replies" is an instance of Object or set null value if "replies" is an empty string.
I neet to make this choice right in the moment of deserializing.
As you can see, now i'm setting Object as replies type because it simply works in both cases (empty string or real object).
But if it possible I want to set the right class to "replies"
@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
@Component
public class RedditCommentDataDTO {
private String subreddit_id;
private String subreddit;
private String id;
private String author;
private float created_utc;
private boolean send_replies;
private String parent_id;
private int score;
private String author_fullname;
private String body;
private boolean edited;
private String name;
private int downs;
private int ups;
private String permalink;
private float created;
private int depth;
private Object replies;
}
Hello everyone,
I really need help with this specific question:
We want to create three types Triangle, Rectangle and Circle. These three types must be subtypes of a Shape abstract type. However, we want to guarantee that the only possible subtypes of Form are these three. How to do it in JAVA?
You're free to use anything... let it be a design pattern, a keyword... any trick!
The only solution I found online is the use of the sealed keyword but I don't think that it's really an accepted solution because its fairly recent...
Thanks in advance!!
what is wrong with burp when it says the jvm cloud not be started the maximum heapsize -Xmx must be to large or an antivirus or firewall cloud block the exucution
I started messing around a bit with Minecraft Clients and made a simple Discord Integration which works fine in the IntelliJ debugger but once exporting JAR and launching the client from the Minecraft Launcher I get exit code 1, what could it be?
From the stack trace in the log files it seems that the StringTranslate
class is attempting to initialize and read from an input stream but encountering a NullPointerException
at the point of creating an instance of Reader
.
I never even touched this.
As the title states, I am creating a personalized text editor with Java FX. Obviously, people have done this before and it would be easy to implement with TextArea, which I have already done.
I want to create a more personalized text editor where you can set fonts, colors, highlight text, etc and maybe other elements in the future.
So, I have implemented my Text Editor as a regular Pane. It listens for key events and writes them into Text Objects, put into TextFlow objects and they are drawn onto the screen based on absolute Y positioning. I have also implementing a line cursor which follows where you are typing.
Some of the things I have not implemented are backspace, double key clicks, etc
I would highly appreciate if someone could read the code and tell me if I'm on the right track.
package org.example.learning.components;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import java.util.ArrayList;
/**
* This is the main class which the user types into to draw on the screen
*/
public class WindowBox {
/**
* Width of the editor Pane
*/
public static final int WIDTH = 600;
/**
* Current text row
*/
private int currentRowIndex = 0;
/**
* Current text which the user is typing into
*/
Text currentText = new Text("");
/**
* Text objects to be drawn on the screen
*/
private ArrayList<TextFlow> textRows = new ArrayList<>();
/**
* Holds all the text elements
*/
Pane pane;
/**
* Blinking cursor
*/
LineCursor lineCursor;
/**
* Users current y Position on the screen
*/
double yPos = 0;
public WindowBox() {
// initialize pane & set styling
pane = new Pane();
pane.setMinSize(600, 600);
pane.getStyleClass().add("border-outline");
textRows.add(new TextFlow(currentText));
drawTextFlow(textRows.get(currentRowIndex));
// add event handlers for when the user types to draw on the screen
initializeFocusHandler();
// draw the cursor
initializeCursor();
}
public WindowBox(ArrayList<TextFlow> textRows) {
super();
this.textRows = textRows;
}
/**
* Runs on initialization to start listening to keypress events
* when the pane is clicked.
*/
public void initializeFocusHandler() {
/**
* Adds focus to the Pane so it can listen to key events
*/
pane.setOnMouseClicked(event -> {
pane.requestFocus();
});
pane.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
// special character clicked. Ex. ctrl, tab, backspace
if (event.getText().isEmpty()) {
// enter key clicked
} else if (event.getCode().equals(KeyCode.ENTER)) {
startNewLine();
// tab key clicked
} else if (event.getCode().equals(KeyCode.TAB)) {
currentText.setText(currentText.getText() + '\t');
// alphanumerical character clicked. Update text and cursor position
} else {
currentText.setText(currentText.getText() + event.getText());
Text text = new Text(event.getText());
lineCursor.updatePosition(currentText.getLayoutX() + currentText.getLayoutBounds().getWidth() + text.getLayoutBounds().getWidth(), textRows.get(currentRowIndex).getLayoutY(), currentText.getLayoutBounds().getHeight());
}
});
}
// add TextFlow to the screen
public void drawTextFlow(TextFlow textFlow) {
pane.getChildren().add(textFlow);
}
// Starts a new line below the current one when the enter key is clicked.
public void startNewLine() {
currentRowIndex++;
updateYPos();
currentText = new Text("");
if (textRows.size() <= currentRowIndex) {
TextFlow newTextFlow = new TextFlow();
newTextFlow.getChildren().add(currentText);
newTextFlow.setLayoutY(yPos);
textRows.add(newTextFlow);
drawTextFlow(textRows.get(currentRowIndex));
}
lineCursor.updatePosition(0, yPos, currentText.getLayoutBounds().getHeight());
}
// update users Y position
public void updateYPos() {
yPos += currentText.getLayoutBounds().getHeight();
}
public Pane getPane() {
return pane;
}
// start the cursor animation and add to the pane
public void initializeCursor() {
lineCursor = new LineCursor(0, 0, 10);
lineCursor.setStroke(Color.BLACK);
lineCursor.startTransition();
pane.getChildren().add(lineCursor);
}
}
In general, why are the metadata categories the way they are? I heard that "group" is for the organization's group, and the "artifact" is the project's name? Why would an organization's group name start with a "com."?
There seems to be a lot of hate for spring webflux and its reactive programming, but I dont seem to see as much hate for Angular's reactive programming (RxJS observables). Is it because they are different domains (frontend vs backend) and therefore maybe reactive programming is appropriate for the frontend whereas it isn't in the backend? Maybe I'm incorrect in my assessment of people's hate for spring webflux vs angular? I'm kinda new at all this, so I'm constantly trying to gauge why people like/dislike certain things in the programming world.
Thanks!
There are two ways that I can think of that would solve this,
Any input would be appreciated. What is the most used way in the industry to go about this?
I'm studying for my intro computer science class that worked with Java all semester. I wanted to get a better understanding of the different types of data structures (Arrays, Array Lists, Linked Lists, HashMaps, Queues, etc.). I know that arrays are built within the java language itself but what about the others. For example, do I always need to create hashmaps through its own class or are expressions and methods built into java that does that for me?
How does this code have 25 statements? I can only count 16 of them.
package vendormachine.users.util;
public class Wallet {
private String brand = "Generic";
private float storedCredit = 0.5f; // using f after a decimal value treats it the as a float(rather than a double)
public Wallet(){}
public Wallet(float startCredit){
this.brand = "Generic";
this.storedCredit = startCredit; // using f after a decimal value treats it the as a float(rather than a double)
}
public Wallet(String brandName, float startCredit){
this.brand = brandName;
this.storedCredit = startCredit; // using f after a decimal value treats it the as a float(rather than a double)
}
//==================
//===Methods
//==================
public void addCredit(float credit){
this.storedCredit += credit;
}
public float getCredit(float retrieve) {
if(retrieve > this.storedCredit){
//TODO replace 'Sys.out's with Log4j
System.out.println("Warning: request exceeds value in wallet!");
System.out.println("Request: " + retrieve + ",\tstored value: " + retrieve);
return 0;
}else {
this.storedCredit -= retrieve;
return retrieve;
}
}
//===============================
//=== 'get'ors
//===============================
public float getAllCredit(){
return this.storedCredit;
}
public String getBrand(String band) {
return this.brand;
}
//===============================
//=== 'set'ors
//===============================
public void setCredit(float credit){
this.storedCredit = credit;
}
public void setBrand(String brand){
this.brand = brand;
}
}
Also how does this other code have 31 statements? I am missing something.
package vendormachine.users;
import vendormachine.users.util.Wallet;
public class Person {
private String name = "";
private Wallet myWallet = null;
public Person(String name){
this.name = name;
}
public Person(String name, Wallet wallet){
this.name = name;
this.myWallet = wallet;
}
//==================
//===Methods
//==================
public float getCredit(float retrieve){
// if our wallet exists.
if(myWallet != null) {
// If what we are trying to retrieve our money within our limits
if(retrieve <= myWallet.getAllCredit()) {
return this.myWallet.getCredit(retrieve);
}else {
System.out.println("WARNING: "+this.name+" does not have the required credit!");
System.out.println("WARNING: Available credit: "+this.myWallet.getAllCredit());
return 0;
}
}else{
//TODO replace with Log4j
System.out.println("WARNING: "+this.name+" does not own a wallet!");
return 0;
}
}
public void addCredit(float credit){
if(myWallet != null) {
this.myWallet.addCredit(credit);
}else{
//TODO replace with Log4j
System.out.println("WARNING: "+this.name+" does not own a wallet!");
}
}
//===============================
//=== 'get'ors
public String getName(){
return this.name;
}
public Wallet getWallet() {
if(myWallet != null) {
return this.myWallet;
}else {
System.out.print("Warning: "+this.name+" does not have a wallet to retrieve.");
return null;
}
}
//===============================
//=== 'set'ors
public void setName(String name){
this.name = name;
}
public void setWallet(Wallet wallet) {
this.myWallet = wallet;
}
}
I’m working on netbeans.
I have a JavaFx project where they gave me many classes with methods i have to use, but there's one method that gives me problems all the time, its the method registerUser() its in the class Acount.class
the code is this one :
package javafxmlapplication;
import java.io.IOException;
import model.*;
import java.io.File;
import java.net.URL;
import java.time.LocalDate;
import java.util.Date;
import java.util.ResourceBundle;
import javafx.beans.property.BooleanProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.stage.FileChooser;
import model.Acount;
import model.User;
import model.AcountDAOException;
import model.AcountDAO;
import model.*;
/**
*
* u/author jsoler
*/
public class FXMLDocumentController implements Initializable {
u/FXML
private Button login_btn;
u/FXML
private Button login_createAccount;
u/FXML
private AnchorPane login_form;
u/FXML
private PasswordField login_password;
u/FXML
private CheckBox login_selectShowPassword;
u/FXML
private TextField login_username;
u/FXML
private PasswordField signup_cPassword;
u/FXML
private Button signup_btn;
u/FXML
private Button signupimg_btn;
u/FXML
private TextField signup_email;
u/FXML
private AnchorPane signup_form;
u/FXML
private ImageView signup_image;
u/FXML
private Button signup_loginAccount;
u/FXML
private TextField signup_name;
u/FXML
private PasswordField signup_password;
u/FXML
private TextField signup_username;
u/FXML
private TextField signup_surname;
private Acount nuevaCuenta;
public void register() throws AcountDAOException, IOException {
//Date date = new Date();
alertMessage alert = new alertMessage();
if (signup_name.getText().isEmpty() || signup_email.getText().isEmpty() || signup_username.getText().isEmpty()
|| signup_password.getText().isEmpty() || signup_cPassword.getText().isEmpty() || signup_surname.getText().isEmpty()) {
alert.errorMessage("All fields are necessary to be filled");
} else if (signup_password.getText().equals(signup_cPassword.getText()) == false) {
// CHECK IF THE VALUE OF PASSWORD FIELDS IS EQUAL TO CONFIRM PASSWORD
alert.errorMessage("Password does not match");
}//else{ nuevaCuenta.registerUser(signup_name.getText(), signup_surname.getText().isEmpty(), signup_email.getText(), signup_username.getText(), signup_password.getText(), image, date.getTime());
Acount nuevacuenta = Acount.getInstance();
Date date = new Date();
boolean result;
result = nuevacuenta.getInstance().registerUser(signup_name.getText(), signup_surname.getText(), signup_email.getText(), signup_username.getText(), signup_password.getText(), signup_image.getImage(), LocalDate.MAX)registerUser(signup_name.getText(), signup_surname.getText().isEmpty(), signup_email.getText(), signup_username.getText(), signup_password.getText(), signup_image.getImage(), date.getTime());
}
public void ButtonImage(ActionEvent event) {
FileChooser fc = new FileChooser();
File selectedFile = fc.showOpenDialog(null);
if (selectedFile != null) {
Image image = new Image(selectedFile.getPath());
signup_image.setImage(image);
} else {
Image defaultIMG = new Image("/avatars/default.png");
signup_image.setImage(defaultIMG);
}
}
//=========================================================
// you must initialize here all related with the object
u/Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
//Date date = new Date();
//if (true == registerUser(signup_name.getText(), signup_surname.getText().isEmpty(), signup_email.getText(), signup_username.getText(), signup_password.getText(), signup_image.getId(), date.getTime()))
}
}
"I am experiencing difficulties in initiating this project as it is only partially built and is displaying some minor errors, despite the correctness of my code. If anyone could assist me in rectifying these issues, I have already pushed my code to GitHub."
Anyhelp would be grateful Thanks
https://github.com/vb51/Spring_user_management.git
Clone this project any you can run it on your IDE
I need some help with a .jar file I created using netbeans for a school task. It's a simple calculator with a JFrame Form. Opening the file will result in a pop up message saying 'A Java Exception has Occured' with a Java Virtual Machine title.
I have no idea how to fix this. The thing is, there are no exceptions or errors that occur when running in Netbeans or command prompt.
I'm currently using the latest version of Java, JDK, and Netbeans and on Windows 10. Any idea how to fix? Or should I start from scratch?
I have main.java and I want to use admin.java, instructor.java and student.java. They are all in the same folder. I don't understand why import admin and other import won't work. I know I need some sort of package but like what? How do I find out the package. This makes no sense because with C++ and Python, they just need to be in the same folder. I'm on visual studio
My final project for AP CSA requires that I create something in java using an API. I want to explore googles vertex ai API; however, I am not quite sure how I can get it to work within replit. If somebody could help me figure this out, or tell me whether it is possible, that would be much appreciated
I am trying to make sure I understand how this class setup works
class Parent {
public void talk() {
System.out.println("parent");
}
}
class Child extends Parent {
public void talk() {
System.out.println("child");
}
}
So my question is when you have no constructors can you always call a default constructor on any class?
For this code can you just do
Parent test = new Parent();
and it will work fine? or in what cases is there not a hidden default constructor
I'm using a Windows 11 PC and just installed eclipse-inst-jre-win64.
Whenever I specify compilation with javac from PowerShell or cmd, I get "C:\Users\user\eclipse\java-2024-03\eclipse" in its place.
Running java --version verifies JDK is still there. I just can't seem to use it anymore.
I also just deleted all the Eclipse directory folders in C:\Users\User, as well as the ".p2" directory folder. I tried it again:
cd "E:\zzzz\zzzz0001\Java\jdk-22.0.1\bin"; .\javac "hllorddt.java"
... and got:
error: illegal unicode escape cd "C:\Users\user\eclipse\java-2024-03\eclipse"; .\eclipse "hllorddt.java"
... even after I deleted all the Eclipse directory folders!
Thanks in advance!
i was wondering if it is possible for buttons to have a custom shape, more specifically a custom rhombus shape