Java Community | Help. Code. Learn.

JCH

Java Community | Help. Code. Learn.

With more than 20,000 members, join one of the biggest and most active Java Communities on Discord! ☕

Join

java-help

❓︱qotw-answers

Override Java awt repaint system (or at least make a paint listener)

I'm trying to hook up Java awt to a glfw window. I have a container (no parent) with some children, like a button. I want to know when the container is trying to repaint an area, then make my own repainting system that sends the painted content to a texture to be rendered. How can I do this? I've tried overriding repaint and paint in the container, and they don't get called. I don't want to have to insert code for all components that I add to the container. Is there some paint listener thingy I can use to do this? Also, kinda related question. If the container is trying to paint a specific section, I create a BufferedImage, create a graphics for it, then tell the container to paint to it, right? But it would just paint the whole window to that image, but I only want that specific section. And is there a better way than the BufferedImage? I need the output to eventually go to a ByteBuffer. Hope this is clear enough...

Expected Identifier

I am new to java. so don't blame me for my little knowledge. I tried creating something and when I run it. it says Project.java:5: error: <identifier> expected what is that?

Drawing a JPanel to a BufferedImage, unexpected results

I'm building a node-based editor. Effectively it's Swing components on a giant carpet, connected with lines to denote relationships and flow of data. To achieve this I have my VisibleFrame with my Donatello JPanel that does the custom rendering. Donatello gets the Swing component of items in the view area, and then draws it like this: ```java private void drawOneNode(Graphics2D g,JPanel panel) { frame.add(panel); frame.pack();...
No description

Problem with an app

Hello, I am making a small project about a restaurant, and I am using MVC and MYSQL, I am having a problem and that is that the controller in my case is managing all the logic of the buttons, but when I run said application these buttons do not work, either. the combo box. I have tried to review my code a lot but I really don't know what could be the problem in this, I only do it to learn how to use MVC but any suggestion to solve the problem would be a great help...
No description

Problem with an app

Hello, I am making a small desktop application, and I am using MVC, I am having a problem and that is that the controller in my case is managing all the logic of the buttons, but when I run said application these buttons do not work, either. the combo box I have tried to review my code a lot but I really don't know what could be the problem in this, I only do it to learn how to use MVC but any suggestion to solve the problem would be a great help...
No description

Optimizing draw function for texured triangle

https://github.com/asdru22/3D-Graphics/blob/rasterization/src/main/java/geom/Triangle.java My current implementation basically implements a rasterization algorithm from scratch, which isn't very efficent. But i don't know how i would otherwise make a triangles texture rotate with it...

Java Multi-Level Scheduler Simulation

Task: Create a Java program (OpenJDK 11) to simulate a multi-level scheduler. Scheduler Details: - High-Priority Level (priority > 0): Uses SJF (Shortest Job First) scheduling. - Low-Priority Level (priority = 0): Uses RR (Round Robin) scheduling with a time slice of 2 units....

Issue with Java Servlet not finding classes

Hi all, i am trying to utilize my existing context config location as well as my app config. The isssue is i am trying to do dependency injection with spring, but want to do it via Java not xml. Can someone help? I am using Java Servlets, With Tomcat and Apache my xml ...

handling lost update problem happening with one thread updating a resource at a time

so i got this quite an interesting problem where i got a piece of code that edits a entity there is one class and a bunch of other classes that inherit it the superclass has a version field for optimistic locking all subclasses are stored in the same jpa repository ...

[JAVA - BEGINEER] Need to press ENTER twice to get the program to output everything

Hello guys, I've tried to search up what it could be, I found out that it could be related to the buffer. However I tried to use sc.nextLine(); to clear the buffer but it didn't seem to help. ```java import java.util.Scanner;...

Homework help for effecting elements in methods

My homework says: "Write a method to gather the required input data (name and sale amount). Don't allow the user to enter a negative number for sales. There will be 2 array parameters in the method, one for names and one for sales, the method will return an array of sales. Hint: Use a do-while loop inside a for loop." I don't know what she is asking me to do. I don't know how to effect a element in one method without it being public or returning it...

[Sping Boot/Mockito/Junit] Lombok Coverege testing

Hello! I'm doing Tests with Mockito, Spring Boot and Lombok. Someone knows how to test a simple class base with only attributes, that is marked with @Data? ```java @Data...

Custom Method to get Token to be provided with OpenFeign proxy requests

So i was making an app which calls a third party API and it requires a auth token with it. I thoight itd be pretty easy to make a RequestInterceptor and make Spring Security do it for me But the endpoint which gives the token has 2 problems. It uses password grant type and it has 2 extra fields "username" and "password" required along eith client id and client secret The ClientRegistration class is final and has no way of making custom implementation So how do i handle getting this token and providing it to OpenFeign when it makes the call...

Declaring isEmpty() and searchString() methods?

Hello! I am a first year CS student working on some code and am troubled by a couple methods. Everytime I try to use an isEmpty() or searchString() method, it says it is undefined while I am constantly seeing that it comes with a sort of package like String. Any help in getting this error fixed is greatly appreciated.
No description

button way too tall

does anyone have any idea as to why the button is very tall? i thought preferredsize would fix it, but apparently not. any suggestions
No description

[ GITHUB ]Contrib graph not working

Hello, I don't know hy but my contrib graph doesn't work when I commit and push, it obviously work when I'm using github to delete or add a repo but github doesn't count my commits. I have always had a different email in my signature from my github and my commit signature and it used to work before....

Architectural Design suggestions on GUI Applications

this might be more of a subjective question in mind knowing there are no one right answer to this question. it is more of a request of suggestions on what you think would be the best practices for creating a GUI application. i am creating a JavaFX application and was thinking of using the MVC pattern but confused by the lots of different MVC implementations made by other people and i felt that it is the wrong design that the business logic has to be placed on the same area as the persistence layer inside the model. i am also confused that lots of implementation would create the instance of model inside their controller class which means you cannot use the same model instance for multiple controller / different screen. for example the SettingsModel would need to be used on multiple Controller classes to set up the same theme on the view, volume, etc. any suggestions on how you usually structure your code in a way that just makes sense from an architectural design perspective....

(Perhaps offtopic) Tell me about play framework

I'm considering rewriting my kotlin (ktor) backend app with scala And as i got, there is no huge scala backend frameworks except for play, so... how is it? Does it worth it? How it feels in comparison with other mvc frameworks like spring? Does it giving enough freedom? Any experience or suggestion is appreciated ^^...