Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7563487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:40:43+00:00 2026-05-30T13:40:43+00:00

I’m making a simple paint program and am stuck with getting a certain part

  • 0

I’m making a simple paint program and am stuck with getting a certain part of a string.
Here’s the trouble – When I save the 9-panel image, it stores the RBG values of each panel to a .txt file. Example:

  1. java.awt.Color[r=0,g=0,b=0]
  2. java.awt.Color[r=255,g=255,b=255]
  3. java.awt.Color[r=255,g=0,b=0]
  4. java.awt.Color[r=0,g=0,b=255]
  5. java.awt.Color[r=0,g=0,b=0]
  6. java.awt.Color[r=255,g=255,b=0]
  7. java.awt.Color[r=255,g=255,b=0]
  8. java.awt.Color[r=255,g=0,b=0]
  9. java.awt.Color[r=0,g=0,b=255]

From here, I call a scanner to read the lines of our file. I just need to find the best way to extract the values inside the [ ] to a String. I’ve tried using a tokenizer to no avail, still being stuck with excess Strings. I’ve tried manipulating characters but again failed. What would be the best way to go about extracting the data from our brackets? AND would it be easier to store the individual r=xxx, b=xxx, g=xxx values to a String[]? Thanks, and here is the source i have so far:

import java.awt.Color;
import java.io.*;
import java.lang.*;
import java.util.*;
//when finished, organize imports (narrow down what imports were used)

public class SaveLoad {

private boolean tryPassed, tryPassed2;

private Formatter x;
//final String[] rawData; will be where the rgb raws are stored

private Scanner xReader;

public void save(Color[] c, String s) {
    //s is the filename
    int counter = c.length;

    //Tries to create a file and, if it does, adds the data to it.
    try{
        x = new Formatter(s+".txt");
        tryPassed = true;
        while(counter>0) {
            x.format("%s. %s\n", (c.length-(counter-1)), c[counter-1]);
            counter--;
        }
        x.close();
    }catch (Exception e){
        e.printStackTrace();
        tryPassed = false;
    }
}

//load will take paramaters of a filename(string); NOTE:::: make the file loaded specify an appendix (ex] .pixmap)
//MAYBE add a load interface with a jDropdownmenu for the filetype? add parameter String filetype.
public void load(String s, String filetype) {
    //loads the file and, if successful, attempts to read it.
    try{
        xReader = new Scanner(new File(s+filetype));
        tryPassed2 = true;
    }catch(Exception e){
        e.printStackTrace();
        tryPassed2 = false;
        System.out.println(s+filetype+" is not a valid file");
    }
    while(xReader.hasNext()&&tryPassed2==true) {
        String inBrackets = xReader.next().substring(17);
        System.out.println(inBrackets);
    }
}
}

Also, ignore my messy notations.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:40:45+00:00Added an answer on May 30, 2026 at 1:40 pm

    The best way is to change the storage format. At least two options:

    • comma-separate values. Store r,g,b on each line. For example 215,222,213. Then you can have line.split(",") to obtain a String[] of the values
    • serialize the whole Color array using ObjectOutputStream
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.