|
My apologies also, i misunderstood the question. The issue is that you need to compare the surnames of each entry, and swap the two entries if the first one is greater than the second. This means swapping all three items in the array entry. The following code should do it.
void sortContact(String[][] contactsArray, int numContacts) {
String[] temp = new String[3];
boolean changes;
do {
changes = false;
for(int i = 0; i < numContacts; i++) {
for(int j = i + 1; j < numContacts; j++) {
if(contactsArray[i][1].compareTo(contactsArray[j][1]) > 0) {
temp[0] = contactsArray[i][0];
temp[1] = contactsArray[i][1];
temp[2] = contactsArray[i][2];
contactsArray[i][0] = contactsArray[j][0];
contactsArray[i][1] = contactsArray[j][1];
contactsArray[i][2] = contactsArray[j][2];
contactsArray[j][0] = temp[0];
contactsArray[j][1] = temp[1];
contactsArray[j][2] = temp[2];
changes = true;
}
}
}
} while (changes == true);
}
|
|
|
|
|
In the following example the setBackground() for the TextField element won't work if it is in a Pane inside a ScrollPane which has the style "-fx-background: transparent;" added, but the problem is that I need it, in order to make the ScrollPane transparent. The weird part is that setBackground() works just fine for the Label element I used in this example. I can not use a CSS file in my original project.
Is this a bug or is there a walk-around for this problem?
To test it, just change the following line
Scene scene = new Scene(scroll);
in this:
Scene scene = new Scene(pane);
public class TestingTextFieldBackground extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Pane pane = new AnchorPane();
pane.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
pane.setPrefWidth(500);
pane.setPrefHeight(500);
pane.setLayoutX(0);
pane.setLayoutY(0);
ScrollPane scroll = new ScrollPane();
scroll.setContent(pane);
scroll.setLayoutX(0);
scroll.setLayoutY(100);
scroll.setPrefWidth(500);
scroll.setPrefHeight(400);
scroll.setHbarPolicy(ScrollBarPolicy.NEVER);
scroll.setVbarPolicy(ScrollBarPolicy.ALWAYS);
scroll.setStyle(
"-fx-background: transparent; -fx-background-color: transparent; -fx-padding: 0; -fx-background-insets: 0;");
Scene scene = new Scene(scroll);
scene.setFill(Color.TRANSPARENT);
Stage stage = new Stage();
stage.setWidth(500);
stage.setHeight(500);
stage.initStyle(StageStyle.TRANSPARENT);
stage.setScene(scene);
Label label = new Label("Bellow you'll find our clients data. (This text is used just as an example)");
label.setLayoutX(0);
label.setLayoutY(0);
label.setTextFill(Color.YELLOW);
label.setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY)));
pane.getChildren().add(label);
int up = 100;
for (int i = 0; i < 50; i++) {
TextField text = new TextField("Client with ID: " + i + ", has " + up + " dollars in account.");
text.setLayoutX(0);
text.setLayoutY(up);
text.setPrefWidth(450);
text.setBackground(new Background(new BackgroundFill(Color.DARKRED, CornerRadii.EMPTY, Insets.EMPTY)));
pane.getChildren().add(text);
up += 80;
}
stage.centerOnScreen();
stage.show();
}
}
modified 27-Nov-19 12:40pm.
|
|
|
|
|
You need a CSS file with the following lines:
.scroll-pane > .viewport {
-fx-background-color: transparent;
}
This will make the gray area transparent. After that if you want to make the whole ScrollPane transparent, then set it a background with .setBackground() function.
Like this, .setBackground() will work just fine for the nodes that you have problem with.
modified 7-Jun-20 16:06pm.
|
|
|
|
|
function exerciseOne(){
(;;)
for(let i=0; i < 7; i++){
console.log("This is i:",i);
}
console.log(str);
}
function exerciseTwo(){
let count = 0;
for (var i = 0; i < 10; i++) {
count ++;
}
return count;
}
modified 10-Nov-19 17:19pm.
|
|
|
|
|
Are you certain this is Java? It looks more like Javascript to me.
|
|
|
|
|
it is I picked the wrong category sorry I am pressed for time and still working on 1 more assignment because i cannot start the final until i figure these two out and the dead line is tonight
|
|
|
|
|
Is there any way you could still take a look at it for me I have moved it to web dev JS thanks I was just in a hurry they moved the deadline up two weeks on us because of the holidays!!
|
|
|
|
|
Does anyone know how to implement global histogram equalization in java. Thank you
|
|
|
|
|
Often, using the search function leads to remarkably appropriate results. Please, use it.
Code Project: Histogram Equalisation in Java[^]
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
hello guys , I want to store biometric attendace machine data to my local SQL Server 2008 R2, how can i do it ? have you any idea about it
|
|
|
|
|
Yes, it is the same as storing any other data to SQL. Create tables and columns to hold whatever data you wish to keep.
|
|
|
|
|
Find manual. Open manual. Turn to section on "interfacing", file formats, stuff like that.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hey guys! I want to develop a program on Java for desktop (Windows and MacOS). My app is on engineering calculations in the construction. I want to hire a company on an outsource basis but I really don’t know how to choose and how to work with them. Maybe you know? I am just trying to get into it. I have no experience and now I am just collecting the info. Maybe you can help?
|
|
|
|
|
Sorry, but this forum is for technical programming questions. If you want to hire outside consultants then I am afraid this is not the place.
|
|
|
|
|
Regardless of who you find, the chances are very high you will get ripped off if you have "no experience"; either intentionally or through misunderstandings. In particular, beware of the "up front" payment. Ask to see the "work" (and retain a copy) before paying anything, or you will be sorry.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
i am automating a login procedure that involves email validation which means there can be 15 minutes till i even get to the start of the automation. so it would be nice to pick up where i left off. how exactly would i do that? i tried
options.setExperimentalOption("debuggerAddress", "127.0.0.1:9222");
but i cant connect to port. any other way?
|
|
|
|
|
Here is that simple but magical Java and Python code. You can easily convert it into a Programming language of your choice.
Java Code
System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("debuggerAddress", "127.0.0.1:9222");
WebDriver driver = new ChromeDriver(options);
System.out.println(driver.getTitle());
|
|
|
|
|
First off I am a newbie and I hope you can understand what I trying to imply, thanks for understanding.
the problem is its seem my method cant pass the string value that inputted by user
Imgur: The magic of the Internet[^]
I want to convert the input of faculty id and name as one string and return it as string when show the data.
this is the uml view, I aware the uml may differ with my code, but the big picture of implementation still same.
[^]
this is the code that solely focus on Faculty view
the fragment of the code is here
Data access object contain method add, delete, show
package penugasan;
public class DataAccesObject {
private Database dataBase;
private long currentFalcutyID;
private String currentFalcutyName;
private long currentStudentID;
private String currentStudentName;
public String string;
public String name;
public DataAccesObject() {
this.dataBase = new Database();
}
public boolean deleteFaculty(Long ID){
final Faculty[] faculty = this.dataBase.getFaculty();
for (int i = 0; i < faculty.length; ++i) {
if (faculty[i] != null && faculty[i].getID().equals(ID)) {
faculty[i] = null;
return true;
}
}
return false;
}
public boolean createFaculty(Long ID, String name){
final Faculty faculty = new Faculty(ID, name);
this.currentFalcutyID = ID;
this.currentFalcutyName = name;
final Faculty[] faculty2 = this.dataBase.getFaculty();
if (faculty2[ID.intValue()] == null) {
faculty2[ID.intValue()] = faculty;
return true;
}
return false;
}
public String readFaculties(){
String string = "";
final Faculty[] faculty = this.dataBase.getFaculty();
for (int i = 0; i < faculty.length; ++i) {
if (faculty[i] != null) {
string = string + faculty[i].getID() + " " + faculty[i].getName() + "\n";
}
}
return string;
}
public Faculty readFacultyByName(String name){
final Faculty[] faculty = this.dataBase.getFaculty();
for (int i = 0; i < faculty.length; ++i) {
if (faculty[i] != null && faculty[i].getName().equals(name)) {
return faculty[i];
}
}
return null;
}
}
Facultyview
package penugasan;
import java.util.Scanner;
public class FacultyView {
private DataAccesObject dao;
public String name;
public FacultyView(DataAccesObject dao) {
this.dao = dao;
}
public void start() {
this.showFaculty(this.dao.readFaculties());
System.out.println("Faculty View Menu : ");
System.out.println("1 Create Faculty");
System.out.println("2 Delete Faculty");
System.out.println("3 Main Menu");
System.out.print("Input your choice : ");
final String nextLine = new Scanner(System.in).nextLine();
if (nextLine.equals("1")) {
this.createFaculty();
}
else if (nextLine.equals("2")) {
this.deleteFaculty();
}
else {
if (nextLine.equals("3")) {
return;
}
System.out.println("Unrecognize Menu\n\n");
this.start();
}
}
public void showFaculty(final String name) {
System.out.println("\n\nList Of Faculty : ");
System.out.println(name);
}
public void createFaculty() {
System.out.print("\nInput ID : ");
final String nextLine = new Scanner(System.in).nextLine();
System.out.print("Input Name : ");
final String nextName = new Scanner(System.in).nextLine();
this.dao.createFaculty(Long.parseLong(nextLine), nextName);
this.start();
}
public void deleteFaculty() {
System.out.print("\nInput ID : ");
this.dao.deleteFaculty(Long.parseLong(new Scanner(System.in).nextLine()));
this.start();
}
}
Class Database to store array of Faculty
package penugasan;
public class Database{
private Faculty[] faculties;
public Database() {
Faculty faculty = new Faculty();
}
public Faculty[] getFaculty() {
this.faculties = new Faculty[10];
return faculties;
}
}
package penugasan;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
DataAccesObject dao = new DataAccesObject();
FacultyView facultyView = new FacultyView(dao);
StudentView studentView = new StudentView(dao);
while(true){
System.out.println("\nMain Menu : ");
System.out.println("1. Student");
System.out.println("2. Faculty");
System.out.println("3. Exit");
System.out.println("Input your choice : ");
Scanner scanner = new Scanner(System.in);
String choice = scanner.nextLine();
if (choice.equals("1")){
studentView.start();
}else if (choice.equals("2")){
facultyView.start();
}else if(choice.equals("3")){
System.exit(0);
}else {
System.out.println("Wrong Choice");
}
}
}
}
for full code here
https://codeshare.io/G88rDB[^]
modified 27-Sep-19 20:58pm.
|
|
|
|
|
Please edit your question and add the proper details, correctly formatted, rather than links to other sites.
You can also find lots of useful information at The Java™ Tutorials[^].
|
|
|
|
|
Is this good, really sorry if the format still messy
|
|
|
|
|
Yes, the formatting is correct, thank you. However, it is no good just dumping the code with a simple, "I want to do ..." statement. You need to explain in proper detail what is not working and where in the code the problem occurs.
|
|
|
|
|
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!
|
|
|
|