|
I'm working on a Java Swing application that will allow users to add index cards to a virtual corkboard. One of the big functionalities I want is for the user to be able to drag and drop cards to reorder them. I don't want to simply position cards at the exact X and Y mouse coordinates where the user releases the mouse button, getting that to work would be relatively trivial. I want the cards to "snap" into place, in a FlowLayout.
Problem is I'm not sure how to accomplish that with the typical MouseListener and MouseMotionListener. Right now my code is organized into a sort of MVC architecture. Here is my code on Github. Everything is just being committed to master for now.
I'm working with a sort of loose MVC type architecture. I have a MainController that has all other child controllers as it's properties. All the other child controllers also take the MainController instance in their constructors. The MainController basically controls the main JFrame of the app and the menu bar. It also acts as a hook for all of the other controllers to communicate with each other.
The ProjectController controls mouse and key events on the "corkboard" area.
The AddCardController is pretty simple, just controls the Add a card window.
Here's where it gets tricky:
The CardController controls mouse events on a particular card. Each card has an instance of the Card model, and it's own CardController, and it's own CardTemplate in the views folder. So every card the user creates is basically an instance of CardController. All the CardControllers are stored in an ArrayList on the MainController. And because every card on the board has it's own CardController, the EditCardController is created inside CardController, so those two are tied together.
This kind of works okay, but I have no idea how to get drag and drop with snapping to work with this architecture (or any architecture for that matter). Each CardTemplate -which is kind of just a component, it extends JPanel but I put it in the views folder for some reason (probably need to change that)- has it's CardController as it's MouseListener.
Can anyone give me advice on how to organize my code so that I can do dragging and dropping with snapping? Should I even hope to use a MouseListener or MouseMotionListener for this?
|
|
|
|
|
|
A SMS API is well-defined software interface which enables code to send short messages via a SMS Gateway.As the infrastructures for SMS communications and the internet are mostly divided, SMS APIs are often used to 'bridge the gap' between telecommunications carrier networks and the wider web. SMS APIs are used to allow web applications to easily send and receive text messages through logic written for standard web frameworks
|
|
|
|
|
Please don't repost if your question does not appear immediately: all of these went to moderation and required a human being to review them for publication. In order to prevent you being kicked off as a spammer, both had to be accepted, and then I have to clean up the spares. Have a little patience, please!
I've deleted the other version.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
There really is no "best" that applies to everyone; what is best for your application is going to depend more on what your capabilities are in any given language
Director of Transmogrification Services
Shinobi of Query Language
Master of Yoda Conditional
|
|
|
|
|
There is no best language, your program should be taken into account.
|
|
|
|
|
Java and Microsoft .NET are two leading technologies intended for the development of desktop and server-side applications. Both platforms enable the use of high-level programming languages to build large-scale applications. While both Java and .NET are often referred to as frameworks, only .NET is actually a framework in the strictest meaning of this word. In fact, the .NET platform uses ASP.NET as a web application framework to allow developers to create web apps.
|
|
|
|
|
How to create restaurant reservation booking using a Java code?
|
|
|
|
|
The same way you would do it in any programming language:
- Gather the requirements of the project
- List the inputs and outputs of the project
- Create an overall design (UML diagrams)
- Create the detailed design for each phase or sub-project
- Design the test requirements
etc.
|
|
|
|
|
Hi guys,
I know how to write code in Java (basic and intermediate level). However, I have very little experience in looking at other peoples' code (experts) and understanding those. I know this is very much required in the industry. I would like to understand how architectures, e.g. MVC and design patterns are implemented by experts.
Therefore, I am asking your recommendations for existing GITHUB projects for learning. I would like to look at a project with the following properties:
1. Built with CORE java. It should have some sort of GUI (maybe JavaFX, which I know isn't CORE java).
2. Followed some architecture and design patterns.
3. It can be a game for example.
4. It should have at least some documentation.
I have searched GUTHUB projects and too much choice has overwhelmed me. Please provide your valuable suggestion so that I can at least start somewhere.
Bye.
|
|
|
|
|
|
Try to see some other forums maybe it will help.
|
|
|
|
|
|
I wanna create a library for sending notification to my android app but i don't know how it works and what kind of data i should give to the function in the class. this is my code for sending notification but i don't know how to put it in the class for using in another sections of the app. This code works in MainActivity
Intent intent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder b = new NotificationCompat.Builder(context);
b.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_launcher_background)
.setTicker("Hearty365")
.setContentTitle("Default notification")
.setContentText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND)
.setContentIntent(contentIntent)
.setContentInfo("Info");
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, b.build());
|
|
|
|
|
My simple HttpServlet is called twice everytime I invoke on my endpoint:
http://cdctst1j:15611/TomSampleServlet/TomSampleServletClient
Could you please help me to take a look?
It is very simple.
My files:
1. WEB-INF\classes\TomSampleServletClient.java:
import java.io.IOException;
import java.net.URL;
import java.net.HttpURLConnection;
import java.lang.ClassNotFoundException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public final class TomSampleServletClient extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
xxxx;
xxxx;
}
}
2. WEB-INF\web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>TomSampleServletClient</servlet-name>
<servlet-class>TomSampleServletClient</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TomSampleServletClient</servlet-name>
<url-pattern>/TomSampleServletClient</url-pattern>
</servlet-mapping>
</web-app>
Thanks so much.
|
|
|
|
|
Knowing not much about "servlets", maybe "mapping" something to itself might be something?
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
I am developing a standalone Java application using an embedded Derby database. Can someone help me understand how I could create all the tables of the database should they not exist within the Java code itself?
|
|
|
|
|
Gregory Guy wrote: Can someone help me understand how I could create all the tables of the database An impossible question to answer. You need to com back with a specific detailed question. And if you are not sure how to use Derby, then go to Apache Derby[^].
|
|
|
|
|
What exactly databases do you want?
|
|
|
|
|
I was playing around with annotation processing and was unable to use generated files directly via an import in my code. Instead I had to prepend the generated class with its complete package. I posted a SO question error: package generated.schema does not exist.
In the end I figured out the reason for this, turned out to be pretty simple, see my answer to the same post. Turned out the error was because I was generating the files at last round of processing, instead of anywhere in between.
So my questions are:
How does generating files at last round vs generating files at in between rounds changes accessing the generated files in code?
Is there a specific reason (Java-related or otherwise) for this behavior?
P.S. I posted the question on SO.
|
|
|
|
|
|
And I want a Ferrari and £1,000,000,000.
But it doesn't work like that. "I want" is not a question.
We're more than willing to help those who have tried and got stuck. But nobody here is going to do your work for you.
If you genuinely don't know where to start, then talk to your teacher.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
hey guys i have this code
table.getModel().addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
if (e.getType() == TableModelEvent.UPDATE)
{
int column = e.getColumn();
if (column == 2 )
{
pricetext.setText(Integer.toString(calculatesum()));
}
}
textsearch.grabFocus();
textsearch.requestFocus();
}
});
both focus methods arent working and i dont know why , thanks for help
|
|
|
|
|