Netbeans6.9.1 Image as icons - java-me

I'm currently using Netbean 6.9.1 and I just want to add some PNG files to my program when it builds. I'm using the files as icons for some of the GUI buttons and labels. But when I select clean and build main project or build main project and execute the JAR file outside the IDE, the icons are missing.
I put the image files into my project folder and basically just add this kinda code in.
the code is working it sisplays the icons but it did nor pick the images for those icons.
void setMainForm(Resources r) {
UIManager.getInstance().setResourceBundle(r.getL10N("localize", "en"));
MainScreenForm main = new MainScreenForm(this, "Business Organiser");
if(mainMenu != null){
main.setTransitionInAnimator(mainMenu.getTransitionInAnimator());
main.setTransitionOutAnimator(mainMenu.getTransitionOutAnimator());
}else{
main.setTransitionOutAnimator(CommonTransitions.createFade(400));
}
mainMenu = main;
int width = Display.getInstance().getDisplayWidth(); //get the display width
elementWidth = 0;
Image[] selectedImages = new Image[DEMOS.length];
Image[] unselectedImages = new Image[DEMOS.length];
final ButtonActionListener bAListner = new ButtonActionListener();
for (int i = 0; i < DEMOS.length; i++) {
Image temp = r.getImage(DEMOS[i].getName() + "_sel.png");
selectedImages[i] = temp;
unselectedImages[i] = r.getImage(DEMOS[i].getName() + "_unsel.png");
final Button b = new Button(DEMOS[i].getName(), unselectedImages[i]);
b.setUIID("DemoButton");
b.setRolloverIcon(selectedImages[i]);
b.setAlignment(Label.CENTER);
b.setTextPosition(Label.BOTTOM);
mainMenu.addComponent(b);
b.addActionListener(bAListner);
b.addFocusListener(new FocusListener() {
public void focusGained(Component cmp) {
if (componentTransitions != null) {
mainMenu.replace(b, b, componentTransitions);
}
}
public void focusLost(Component cmp) {
}
});
demosHash.put(b, DEMOS[i]);
elementWidth = Math.max(b.getPreferredW(), elementWidth);
}
if(cols == 0){
cols = width / elementWidth;
}
int rows = DEMOS.length / cols;
mainMenu.setLayout(new GridLayout(rows, cols));
mainMenu.setDragMode(true);
mainMenu.addCommand(exitCommand);
mainMenu.addCommand(aboutCommand);
mainMenu.addCommand(rtlCommand);
mainMenu.addCommand(dragModeCommand);
mainMenu.addCommand(runCommand);
mainMenu.addCommandListener(this);
mainMenu.show();
}

You need to put the images in the src folder so they get packaged in the jar (use 7zip on the jar to see what went in). You didn't provide the image URL e.g icon in src root should work like this:
"/icon.png"

Related

How are assemblies located and loaded in .NET 5+?

I am currently elaborating which content I should use in the different version numbers, so I read What are differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion? and many other posts and articles.
Based on SemVer, I would increase the minor version number if I make backwards compatible changes. I understand and like this concept, and I want to use it.
This answer on the above linked post has good explanations on the different version numbers, but it also says that changing AssemblyVersion would require recompiling all dependent assemblies and executables.
I did a quick test:
testVersionLib.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>abc.snk</AssemblyOriginatorKeyFile>
<AssemblyVersion>3.4.5.6</AssemblyVersion>
</PropertyGroup>
</Project>
project testVersionLib: class1.cs
using System;
namespace testVersionLib
{
public class Class1
{
public string m_versionText = "3.4.5.6";
}
}
project testVersionExe: program.cs
using System;
using System.Diagnostics;
namespace testVersionExe
{
class Program
{
static void Main (string[] args)
{
Console.WriteLine ("Hello World!");
PrintFileVersion ();
PrintAssemblyFullName ();
}
private static void PrintAssemblyFullName ()
{
Console.WriteLine ("m_versionText: " + new testVersionLib.Class1 ().m_versionText);
Console.WriteLine ("DLL Assembly FullName: " + System.Reflection.Assembly.GetAssembly (typeof (testVersionLib.Class1)).FullName);
}
private static void PrintFileVersion ()
{
Console.WriteLine ("DLL FileVersion: " + FileVersionInfo.GetVersionInfo ("testVersionLib.dll").FileVersion);
}
}
}
and found that this may apply to .Net Framework, but it obviously does not apply to .NET 5 (and most likely .NET 6 and above as well, and maybe previous versions of .NET Core): I created a .NET 5 C# console app with AssemblyVersion 1.2.3.4 and strong name. This EXE references a DLL with AssemblyVersion 3.4.5.6 and strong name. The DLL compiled with different versions and is placed in the EXE's folder without compiling that one again.
The results:
The EXE fails to start if the DLL version is below 3.4.5.6 (e.g. 3.4.5.5, 3.4.4.6, 3.3.5.6), which makes sense.
The EXE successfully runs if the DLL version is equal to or above the version that was used to created the app (equal: 3.4.5.6; above: 3.4.5.7, 3.4.6.6, 3.5.5.6, 4.4.5.6).
This answer only says that
[...] .Net 5+ does not (by default) require that the assembly version used at runtime match the assembly version used at build time.
but it does not explain why and how.
How are assemblies located, resolved and loaded in .NET 5?
If someone wants to repeat my test with the compiled files, here's the 7z archive, encoded as PNG:
To decode the image, save it as PNG and use this code:
static void Main (string[] args)
{
string dataPath = #"c:\temp\net5ver.7z";
string imagePath = #"c:\temp\net5ver.7z.png";
string decodedDataPath = #"c:\temp\net5ver.out.7z";
int imageWidth = 1024;
Encode (dataPath, imagePath, imageWidth);
Decode (imagePath, decodedDataPath);
}
public static void Decode (string i_imagePath, string i_dataPath)
{
var bitmap = new Bitmap (i_imagePath);
var bitmapData = bitmap.LockBits (new Rectangle (Point.Empty, bitmap.Size), System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
byte[] dataLengthBytes = new byte[4];
Marshal.Copy (bitmapData.Scan0, dataLengthBytes, 0, 4);
int dataLength = BitConverter.ToInt32 (dataLengthBytes);
int imageWidth = bitmap.Width;
int dataLines = (int)Math.Ceiling (dataLength / (double)imageWidth);
if (bitmap.Height != dataLines + 1)
throw new Exception ();
byte[] row = new byte[imageWidth];
List<byte> data = new();
for (int copyIndex = 0; copyIndex < dataLines; copyIndex++)
{
int rowStartIndex = imageWidth * (copyIndex + 1);
Marshal.Copy (IntPtr.Add (bitmapData.Scan0, rowStartIndex), row, 0, row.Length);
data.AddRange (row.Take (dataLength - data.Count));
}
bitmap.UnlockBits (bitmapData);
System.IO.File.WriteAllBytes (i_dataPath, data.ToArray ());
}
public static void Encode (string i_dataPath,
string i_imagePath,
int i_imageWidth)
{
byte[] data = System.IO.File.ReadAllBytes (i_dataPath);
int dataLines = (int)Math.Ceiling (data.Length / (double)i_imageWidth);
int imageHeight = dataLines + 1;
var bitmap = new Bitmap (i_imageWidth, imageHeight, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
var palette = bitmap.Palette;
for (int index = 0; index < byte.MaxValue; index++)
palette.Entries[index] = Color.FromArgb (index, index, index);
bitmap.Palette = palette;
var bitmapData = bitmap.LockBits (new Rectangle (Point.Empty, bitmap.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, bitmap.PixelFormat);
Marshal.Copy (BitConverter.GetBytes (data.Length), 0, bitmapData.Scan0, 4);
for (int copyIndex = 0; copyIndex < dataLines; copyIndex++)
{
int dataStartIndex = i_imageWidth * copyIndex;
int rowStartIndex = i_imageWidth * (copyIndex + 1);
byte[] row = data.Skip (dataStartIndex).Take (i_imageWidth).ToArray ();
Marshal.Copy (row, 0, IntPtr.Add (bitmapData.Scan0, rowStartIndex), row.Length);
}
bitmap.UnlockBits (bitmapData);
bitmap.Save (i_imagePath);
}

How to unite gameobject meshes?

Because of I made my house from the unity editor I can't remove this mesh borders. I tried MeshCombiner but it just connects all of the meshes in one mesh borders still exist. I know I can make it from Blender or something like this but is there any one to remove from unity?
Screen Shot: http://imgur.com/a/1XALE
Maybe you are looking for CombineMeshes. An example is
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class ExampleClass : MonoBehaviour {
void Start() {
MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
CombineInstance[] combine = new CombineInstance[meshFilters.Length];
int i = 0;
while (i < meshFilters.Length) {
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
meshFilters[i].gameObject.active = false;
i++;
}
transform.GetComponent<MeshFilter>().mesh = new Mesh();
transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
transform.gameObject.active = true;
}
}

Unity 3D, WWW function works in the editor yet when I build to PC the audio files are not loading or playing

Yeh I know the function works fine in the editor but when I build to PC no luck in getting the audio imported. The Audio source and listener are loaded in another class at runtime. This works perfectly when running it in the editor but when i build the game to PC no luck when trying to play audio at runtime.
# void Start()
{
if (aSource == null && aListener == null)
{
//creating the audio sources for the music to play
//and audio listener in order to hear the music
aSource = gameObject.AddComponent<AudioSource>();
aListener = gameObject.AddComponent<AudioListener>();
toggleBrowser = false;
}
// Getting the component play Button
playButton = GameObject.FindGameObjectWithTag("PlayButton");
button = playButton.GetComponent<Button>();
}
public void toggleFileBroswer()
{
// Toggle the file browser window
toggleBrowser = !toggleBrowser;
}
public void OnGUI()
{
// File browser, cancel returns to menu and select chooses music file to load
if (toggleBrowser)
{
if (fb.draw())
{
if (fb.outputFile == null)
{
Application.LoadLevel("_WaveRider_Menu");
toggleBrowser = !toggleBrowser;
}
else
{
Debug.Log("Ouput File = \"" + fb.outputFile.ToString() + "\"");
// Taking the selected file and assigning it a string
userAudio = fb.outputFile.ToString();
//Starting the load process for the file
StartCoroutine(LoadFilePC(userAudio));
toggleBrowser = false;
startLoad = true;
}
}
}
}
void Update()
{
// Making the play button inactive untill the file has loaded
if (startLoad)
{
loadTime += Time.deltaTime;
}
if (loadTime >= 5)
{
button.interactable = true;
}
}
public void playTrack()
{
// Dont destroy these GameObjects as we load the next scene
Object.DontDestroyOnLoad(aSource);
Object.DontDestroyOnLoad(aListener);
//assigns the clip to the audio source and play it
aSource.clip = aClip;
aSource.Play();
Debug.Log("Playing track");
}
IEnumerator LoadFilePC(string filePath)
{
filePath = userAudio;
print("loading " + filePath);
//Loading the string file from the File browser
WWW www = new WWW("file:///" + filePath);
//create audio clip from the www
aClip = www.GetAudioClip(false);
while (!aClip.isReadyToPlay)
{
yield return www;
}
}
public void exit()
{
// Exit game, only works on built .exe not in the editor window
Application.Quit();
}
}

How to get drives( 'C' or 'E' or 'F' )available in a system?

I am developing an Bootstrapper application. When we move to the installation location selection wizard, we can have a browse option to change the location of our setup installation.
When we clock that browse option, i need to show only the drives( 'C', 'D' and 'F') available in a system. When we select the drive, it will not expand. i need that drive alone (Ex: C:) in the installation location text in the installation wizard.
Can anyone please guide me that how to achieve my requirement?
My code:
private void btn_Browse_Click(object sender, EventArgs e)
{
txt_InstallLocation.Focus();
FBD_Source.RootFolder = Environment.SpecialFolder.Desktop;
if (FBD_Source.ShowDialog() == DialogResult.OK)
{
txt_InstallLocation.TextBox.Text = FBD_Source.SelectedPath;
BA.Model.Bootstrapper.Engine.StringVariables["APPDIR"] = FBD_Source.SelectedPath + "\\";
}
}
I need to modify the below line of code.
FBD_Source.RootFolder = Environment.SpecialFolder.Desktop;
Can anyone please assist me to proceed further or direct me in right path?
Your can find the available drives like this.
var drives = System.Environment.GetLogicalDrives();
foreach (string d in drives)
Console.WriteLine(d);
Don't use the FolderBrowserDialog.
Create a form with a dynamically created radiobutton/list and make the user select one of those options
Something like this
var drives = System.Environment.GetLogicalDrives();
Form selectionForm = new Form() { MaximizeBox = false, FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog, StartPosition = FormStartPosition.CenterScreen };
ListBox lb = new ListBox() { Dock = DockStyle.Fill };
foreach (var item in drives)
lb.Items.Add(item);
selectionForm.Controls.Add(lb);
Button btnOk = new Button() { Dock = DockStyle.Left, Width = selectionForm.Width / 2 };
btnOk.Text = "OK";
Button btnCancel = new Button() { Dock = DockStyle.Right, Width = selectionForm.Width / 2 };
btnCancel.Text = "Cancel";
Panel bottomPanel = new Panel() { Dock = DockStyle.Bottom, Height = 50 };
bottomPanel.Controls.Add(btnOk);
bottomPanel.Controls.Add(btnCancel);
selectionForm.Controls.Add(bottomPanel);
selectionForm.ShowDialog();
MessageBox.Show(lb.SelectedItem.ToString());

Show loading form while parsing XML in J2ME

I am parsing xml from remote server using kxml parser. I am using the following code to parse xml
public void validateUser(String name, String password, String mobile, String code)
{
Display.getDisplay(parent).setCurrent(new LoadingBarCanvas(parent));
ReadXML xmlThread = new ReadXML();
xmlThread.start();
int count = 0;
URL = "http://www.acb.info/mobapp/Web_service/checkLogin.php?mobile=" + mobile + "&userId=dbz&password=123&code=" + code + "&output=xml";
while (xmlThread.isAlive())
{
if (count == 0)
{
System.out.println("thread is alive");
}
count++;
}
StringBuffer sb = new StringBuffer();
System.out.println("bookVector " + bookVector.size());
for (int i = 0; i < bookVector.size(); i++) {
ChapterClass book = (ChapterClass) bookVector.elementAt(i);
sb.append("\n");
sb.append("Name : ");
sb.append(book.getName());
status = book.getName();
sb.append("\n");
sb.append("Descrition : ");
sb.append(book.getDescription());
smcID = book.getDescription();
userName.setString(book.getRating());
//=book.getRating();
sb.append("\n");
}
System.out.println(sb.toString());
if (status.equalsIgnoreCase("Sucess.."))
{
StoreData("smcid",smcID);
StoreData("userid",userName.getString());
showInputLogInSuccessfull();
}
else
{
showInputLogInFailed();
}
}
I want to show loading Form from another class while xml is parsing. I have tried Display.getDisplay(parent).setCurrent(new LoadingBarCanvas(parent)); to display loading form but it don't show the loading Form. So how can I solve this problem ?
you can use the GIF file for loading screen
Here you can find the sample code
if u r using the Netbeans then
Go to library->Add Netbeans MIDP compaonent
U'll get the class of netbeans.splachscreen,netbeans.waitingsceen
Which u can use and integrate in ur code

Resources