All compiler errors have to be fixed before you can enter playmode - unity3d

Hello when I click play I see this error:
All compiler errors have to be fixed before you can enter playmode!
UnityEditor.SceneView:ShowCompileErrorNotification ()
Hello, I am a learning programmer and I need some help with the code. I do not know why, but the program does not start, it just displayed a message, please help me because I care about the code. In the screen you can see only one code name: Menu Glowne when is this code.
code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MenuGlowne : MonoBehaviour {
public string obecneOkno = "";
Vector2 srodekEkranu;
string login = "";
string haslo = "";
string email = "";
void Start () {
srodekEkranu = new Vector2(Screen.width/2-100, Screen.height/2-15);
}
void Update()
{
if(input.getKey (KeyCode.Escape)){
obecneOkno = "login";
}
}
void OnGUI(){
switch (obecneOkno){
case "login":
PokazOknoLogowania();
break;
case "rejestracja":
PokazOknoRejestracji();
break;
case "menuGlowne":
break;
case "lobby":
break;
}
}
void PokazOknoLogowania(){
login = GUI.TextField (new Rect(srodekEkranu.x, srodekEkranu.y, 200, 30), login, 20, "box");
haslo = GUI.PasswordField (new Rect(srodekEkranu.x, srodekEkranu.y+35, 200, 30),haslo, '*', 20, "box");
if (GUI.Button (new Rect(srodekEkranu.x, srodekEkranu.y+75, 200, 30),"Zaloguj")){
GenerujLinkLoginu();
}
if (GUI.Button (new Rect(srodekEkranu.x, srodekEkranu.y+140, 200, 30),"Rejestracja")){
obecneOkno = "rejestracja";
}
}
void PokazOknoRejestracji(){
login = GUI.TextField (new Rect(srodekEkranu.x, srodekEkranu.y-70, 200, 30), login, 20, "box");
GUI.Label (new Rect(srodekEkranu.x-205, srodekEkranu.y-70, 100, 30),"Podaj login:");
email = GUI.TextField (new Rect(srodekEkranu.x, srodekEkranu.y-35, 200, 30), email, 100, "box");
GUI.Label (new Rect(srodekEkranu.x-205, srodekEkranu.y-35, 100, 30),"Podaj E-mail:");
haslo = GUI.PasswordField (new Rect(srodekEkranu.x, srodekEkranu.y+35, 200, 30),haslo, '*', 20, "box");
GUI.Label (new Rect(srodekEkranu.x-205, srodekEkranu.y+35, 100, 30),"Podaj Hasło:");
if (GUI.Button (new Rect(srodekEkranu.x, srodekEkranu.y+75, 200, 30),"Zarejestruj")){
GenerujLinkRejestracji();
}
}
void GenerujLinkLoginu(){
WWWForm w = new WWWForm();
w.AddField ("login",login);
w.AddField ("haslo",haslo);
WWW link = new WWW("http://localhost/unity/login.php", w);
StartCoroutine (Zaloguj (link));
}
IEnumerator Zaloguj(WWW link) {
yield return link;
Debug.Log (link.text);
}
void GenerujLinkRejestracji(){
WWWForm w = new WWWForm();
w.AddField ("login",login);
w.AddField ("haslo",haslo);
w.AddField ("email",email);
WWW link = new WWW("http://localhost/unity/register.php", w);
StartCoroutine (Zarejestruj (link));
}
IEnumerator Zarejestruj(WWW link){
yield return link;
Debug.Log (link.text);
}
}

input.getKey (KeyCode.Escape)
Here the caption is wrong it should be
Input.GetKey(KeyCode.Escape)

It means there is another error that you need to fix before it will run. Click on "console", to the bottom left, and make sure errors are visible (right most button in the top left of the window.

Related

My Unity (ZXing/XR) QRCode reader isn't presenting the decoded info. What am I doing wrong?

This is the code I am using for QR Scan. It uses XR for Camera input and ZXing to decode the QR Code. I have been at this for 3 days and still have no clue what I am doing wrong. I do not know whether it is that code isn't able to decode the QR, or it can but isn't able to print it out on Output text. Any help would be greatly appreciated. Thank you! :)
These are the libraries I am using :
using System.Collections;
using UnityEngine;
using UnityEngine.XR.ARSubsystems;
using UnityEngine.XR.ARFoundation;
using ZXing;
using TMPro;
This is the code :
IBarcodeReader _reader;
ARCameraManager _arCam;
AudioSource _audioSrc;
ARRaycastManager _arRay;
private Texture2D _arTexture;
private TextMeshPro _outputText;
private void Awake()
{
_arCam = FindObjectOfType<ARCameraManager>();
_audioSrc = FindObjectOfType<AudioSource>();
_arRay = FindObjectOfType<ARRaycastManager>();
_reader = new BarcodeReader();
_arCam.frameReceived += OnCameraFrameReceived; //When camera receives frame.
}
//Fires off when Frame is received.
void OnCameraFrameReceived(ARCameraFrameEventArgs eventArgs)
{
if ((Time.frameCount % 15) == 0)
{
XRCpuImage _image;
if(_arCam.TryAcquireLatestCpuImage(out _image))
{
StartCoroutine(ProcessQRCode(_image));
_image.Dispose();
}
}
}
//Processes the QR Code in the _image.
IEnumerator ProcessQRCode(XRCpuImage _image)
{
var request = _image.ConvertAsync(new XRCpuImage.ConversionParams { inputRect = new RectInt(0, 0, _image.width, _image.height),
outputDimensions = new Vector2Int(_image.width / 2, _image.height / 2),
outputFormat = TextureFormat.RGB24
});
while (!request.status.IsDone())
yield return null;
if (request.status != XRCpuImage.AsyncConversionStatus.Ready)
{
Debug.LogErrorFormat("Request failed with status {0}", request.status);
request.Dispose();
yield break;
}
var rawData = request.GetData<byte>();
if(_arTexture == null)
{
_arTexture = new Texture2D(
request.conversionParams.outputDimensions.x,
request.conversionParams.outputDimensions.y,
request.conversionParams.outputFormat,
false
);
}
_arTexture.LoadRawTextureData(rawData);
_arTexture.Apply();
byte[] barcodeBitmap = _arTexture.GetRawTextureData();
LuminanceSource source = new RGBLuminanceSource(barcodeBitmap, _arTexture.width, _arTexture.height);
var result = _reader.Decode(source);
if(result != null)
{
var QRContents = result.Text;
_outputText.text = QRContents;
_audioSrc.Play();
}
}

Xamarin Forms Android & iOS Background Fetch

Hello everyone,
I want to request to my rest api in Xamarin forms , download data and comparing it another one if it suits conditions existing a local notification on background while application is closed.
How can i do this with a interval like two minutes on background?
I’m researching few days but i could not find anything.
Anyone help me please ?
Thanks :)
Do you mean you want it works when your app is closed ? if yes,you could consider using Foreground Services
here is a simple sample for Android you could refer to,you could change the runnable according your needs.
1.Create a Service MyService.cs :
[Service(Enabled = true)]
public class MyService : Service
{
private Handler handler;
private Action runnable;
private bool isStarted;
private int DELAY_BETWEEN_LOG_MESSAGES = 5000;
private int NOTIFICATION_SERVICE_ID = 1001;
private int NOTIFICATION_AlARM_ID = 1002;
private string NOTIFICATION_CHANNEL_ID = "1003";
private string NOTIFICATION_CHANNEL_NAME = "MyChannel";
public override void OnCreate()
{
base.OnCreate();
handler = new Handler();
//here is what you want to do always, i just want to push a notification every 5 seconds here
runnable = new Action(() =>
{
if (isStarted)
{
DispatchNotificationThatAlarmIsGenerated("I'm running");
handler.PostDelayed(runnable, DELAY_BETWEEN_LOG_MESSAGES);
}
});
}
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
if (isStarted)
{
// service is already started
}
else
{
CreateNotificationChannel();
DispatchNotificationThatServiceIsRunning();
handler.PostDelayed(runnable, DELAY_BETWEEN_LOG_MESSAGES);
isStarted = true;
}
return StartCommandResult.Sticky;
}
public override void OnTaskRemoved(Intent rootIntent)
{
//base.OnTaskRemoved(rootIntent);
}
public override IBinder OnBind(Intent intent)
{
// Return null because this is a pure started service. A hybrid service would return a binder that would
// allow access to the GetFormattedStamp() method.
return null;
}
public override void OnDestroy()
{
// Stop the handler.
handler.RemoveCallbacks(runnable);
// Remove the notification from the status bar.
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.Cancel(NOTIFICATION_SERVICE_ID);
isStarted = false;
base.OnDestroy();
}
private void CreateNotificationChannel()
{
//Notification Channel
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, NotificationImportance.Max);
notificationChannel.EnableLights(true);
notificationChannel.EnableVibration(true);
notificationChannel.SetVibrationPattern(new long[] { 100, 200, 300, 400, 500, 400, 300, 200, 400 });
NotificationManager notificationManager = (NotificationManager)this.GetSystemService(Context.NotificationService);
notificationManager.CreateNotificationChannel(notificationChannel);
}
//start a foreground notification to keep alive
private void DispatchNotificationThatServiceIsRunning()
{
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.SetDefaults((int)NotificationDefaults.All)
.SetSmallIcon(Resource.Drawable.Icon)
.SetVibrate(new long[] { 100, 200, 300, 400, 500, 400, 300, 200, 400 })
.SetSound(null)
.SetChannelId(NOTIFICATION_CHANNEL_ID)
.SetPriority(NotificationCompat.PriorityDefault)
.SetAutoCancel(false)
.SetContentTitle("Mobile")
.SetContentText("My service started")
.SetOngoing(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.From(this);
StartForeground(NOTIFICATION_SERVICE_ID, builder.Build());
}
//every 5 seconds push a notificaition
private void DispatchNotificationThatAlarmIsGenerated(string message)
{
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
Notification.Builder notificationBuilder = new Notification.Builder(this, NOTIFICATION_CHANNEL_ID)
.SetSmallIcon(Resource.Drawable.Icon)
.SetContentTitle("Alarm")
.SetContentText(message)
.SetAutoCancel(true)
.SetContentIntent(pendingIntent);
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.Notify(NOTIFICATION_AlARM_ID, notificationBuilder.Build());
}
}
2.in your activity :
protected override void OnResume()
{
base.OnResume();
StartMyRequestService();
}
public void StartMyRequestService()
{
var serviceToStart = new Intent(this, typeof(MyService));
StartService(serviceToStart);
}

Cloud load failed with error code 7 using Unity GoolePlayGames plugin

I get the following log during on-device debugging
Error:
*** [Play Games Plugin DLL] ERROR: Cloud load failed with status code 7
Basically the OnStateLoaded() callback function always returns the boolean success = false and I can't figure out the reason why.
All that the plugin debugging logs mention is "Cloud load failed with status code 7".
According to the android doc, 7 is a generic "developer error", see https://developer.android.com/reference/com/google/android/gms/appstate/AppStateStatusCodes.html#STATUS_DEVELOPER_ERROR
I tried a quick sample and everything worked ok. Here are my steps:
Created a new game in the play console
(https://play.google.com/apps/publish)
Made sure Saved Games is set
to ON
Linked an Android Application Remembering the application ID
(the number after the title) and the package ID
Created a new project in Unity
Added the play games plugin (Assets/Import Package.../Custom
Package)
Set the application ID (Google Play Games/Android Setup...)
Switched the platform to Android (File/Build Settings...)
Set the player settings (bundle identifier and the keystore info)
Added a new script component to the camera
Saved everything and hit build and run.
Here are the contents:
using UnityEngine;
using System.Collections;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using System;
public class SaveSample : MonoBehaviour {
System.Action<bool> mAuthCallback;
GameData slot0;
void Start () {
slot0 = new GameData(0,"waiting for login....");
mAuthCallback = (bool success) => {
if (success) {
Debug.Log("Authentication was successful!");
slot0.Data =" loading....";
slot0.LoadState();
}
else {
Debug.LogWarning("Authentication failed!");
}
};
// make Play Games the default social implementation
PlayGamesPlatform.Activate();
// enable debug logs
PlayGamesPlatform.DebugLogEnabled = true;
//Login explicitly for this sample, usually this would be silent
PlayGamesPlatform.Instance.Authenticate(mAuthCallback, false);
}
protected void OnGUI() {
Screen.fullScreen = true;
int buttonHeight = Screen.height / 20;
int buttonWidth = Screen.width / 5;
GUI.skin.label.fontSize = 60;
GUI.skin.button.fontSize = 60;
Rect statusRect = new Rect(10,20,Screen.width,100);
Rect dataRect = new Rect( 10, 150, Screen.width,100);
Rect b1Rect = new Rect(10, 400, buttonWidth, buttonHeight);
Rect b2Rect = new Rect(b1Rect.x + 20 + buttonWidth,
b1Rect.y, buttonWidth, buttonHeight);
if(!Social.localUser.authenticated) {
if(GUI.Button(b1Rect, "Signin")) {
Social.localUser.Authenticate(mAuthCallback);
}
}
else {
// logged in, so show the load button and the contents of the saved data.
if(GUI.Button(b1Rect, "Load")) {
slot0.LoadState();
}
GUI.Label(dataRect, slot0.Data);
}
if(GUI.Button(b2Rect, "Save")) {
// just save a string, incrementing the number on the end.
int idx = slot0.Data.IndexOf("_");
if (idx > 0) {
int val = Convert.ToInt32(slot0.Data.Substring(idx+1));
val++;
slot0.Data = "Save_" + val;
}
else {
slot0.Data = "Save_0";
}
slot0.SaveState();
}
GUI.Label(statusRect, slot0.State);
}
// Class to handle save/load callbacks.
public class GameData : OnStateLoadedListener {
int slot;
string data;
string state;
public GameData(int slot, string data) {
this.slot = slot;
this.data = data;
this.state = "Initialized, modified";
}
public void LoadState() {
this.state += ", loading";
((PlayGamesPlatform)Social.Active).LoadState(0, this);
}
public void SaveState() {
byte[] bytes = new byte[data.Length * sizeof(char)];
System.Buffer.BlockCopy(data.ToCharArray(), 0, bytes, 0, bytes.Length);
this.state += ", saving";
((PlayGamesPlatform) Social.Active).UpdateState(slot, bytes, this);
}
public void OnStateLoaded(bool success, int slot, byte[] data) {
if (success) {
Debug.Log ("Save game slot : " + slot + " loaded: " + data);
if (data != null) {
char[] chars = new char[data.Length / sizeof(char)];
System.Buffer.BlockCopy(data, 0, chars, 0, data.Length);
this.data = new string(chars);
this.state = "loaded";
} else {
Debug.Log ("Saved data is null");
this.data = "";
this.state = "loaded, but empty";
}
} else {
// handle failure
Debug.LogWarning ("Save game slot : " + slot + " failed!: ");
this.data = "";
this.state = "loading failed!";
}
}
public byte[] OnStateConflict(int slot, byte[] local, byte[] server) {
// resolve conflict and return a byte[] representing the
// resolved state.
Debug.LogWarning("Conflict in saved data!");
state = "conflicted";
// merge or resolve using app specific logic, here
byte[] resolved = local.Length > server.Length ? local : server;
char[] chars = new char[resolved.Length / sizeof(char)];
System.Buffer.BlockCopy(resolved, 0, chars, 0, resolved.Length);
this.data = new string(chars);
return resolved;
}
public void OnStateSaved(bool success, int slot) {
Debug.Log ("Save game slot : " + slot + " success: " + success);
state = "saved";
}
public string Data {
get {
return data;
}
set {
data = value;
state += ", modified";
}
}
public int Slot {
get {
return slot;
}
}
public string State {
get {
return state;
}
}
}
}
The error code 7 is because the Cloud Save API has been deprecated and is only currently accessible to existing games that have used the API. The Unity plugin version 0.9.11 has been updated to use the SavedGames API.
I tried a quick sample and everything worked ok. Here are my steps:
Created a new game in the play console
(https://play.google.com/apps/publish)
Made sure Saved Games is set to ON
Linked an Android Application Remembering the application ID
(the number after the title) and the package ID Created a new
project in Unity
Added the play games plugin (Assets/Import
Package.../Custom Package)
Set the application ID (Google Play
Games/Android Setup...)
Switched the platform to Android (File/Build
Settings...)
Set the player settings (bundle identifier and the
keystore info)
Added a new script component to the camera Saved
everything and hit build and run.
Here is my script:
using UnityEngine;
using System.Collections;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using System;
using GooglePlayGames.BasicApi.SavedGame;
public class SaveSample : MonoBehaviour {
System.Action<bool> mAuthCallback;
GameData slot0;
bool mSaving;
private Texture2D mScreenImage;
// Use this for initialization
void Start () {
slot0 = new GameData("New game");
mAuthCallback = (bool success) => {
if (success) {
Debug.Log("Authentication was successful!");
slot0.State = "Click load or save";
}
else {
Debug.LogWarning("Authentication failed!");
}
};
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.EnableSavedGames()
.Build();
PlayGamesPlatform.InitializeInstance(config);
// Activate the Play Games platform. This will make it the default
// implementation of Social.Active
PlayGamesPlatform.Activate();
// enable debug logs (note: we do this because this is a sample; on your production
// app, you probably don't want this turned on by default, as it will fill the user's
// logs with debug info).
PlayGamesPlatform.DebugLogEnabled = true;
//Login explicitly for this sample, usually this would be silent
PlayGamesPlatform.Instance.Authenticate(mAuthCallback, false);
}
public void CaptureScreenshot() {
mScreenImage = new Texture2D(Screen.width, Screen.height);
mScreenImage.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
mScreenImage.Apply();
}
protected virtual void OnGUI() {
Screen.fullScreen = true;
int buttonHeight = Screen.height / 20;
int buttonWidth = Screen.width / 5;
GUI.skin.label.fontSize = 60;
GUI.skin.button.fontSize = 60;
Rect statusRect = new Rect(10,20,Screen.width,200);
Rect dataRect = new Rect( 10, 250, Screen.width,100);
Rect b1Rect = new Rect(10, 800, buttonWidth, buttonHeight);
Rect b2Rect = new Rect(b1Rect.x + 20 + buttonWidth, b1Rect.y, buttonWidth, buttonHeight);
if(!Social.localUser.authenticated) {
if(GUI.Button(b1Rect, "Signin")) {
Social.localUser.Authenticate(mAuthCallback);
}
}
else {
if(GUI.Button(b1Rect, "Load")) {
mSaving = false;
((PlayGamesPlatform)Social.Active).SavedGame.ShowSelectSavedGameUI("Select game to load",
4,false,false,SavedGameSelected);
}
GUI.Label(dataRect, slot0.Data);
}
if(GUI.Button(b2Rect, "Save")) {
int idx = slot0.Data.IndexOf("_");
if (idx > 0) {
int val = Convert.ToInt32(slot0.Data.Substring(idx+1));
val++;
slot0.Data = "Save_" + val;
}
else {
slot0.Data = "Save_0";
}
mSaving = true;
CaptureScreenshot();
((PlayGamesPlatform)Social.Active).SavedGame.ShowSelectSavedGameUI("Save game progress",
4,true,true,SavedGameSelected);
}
GUI.Label(statusRect, slot0.State);
}
public void SavedGameSelected(SelectUIStatus status, ISavedGameMetadata game) {
if (status == SelectUIStatus.SavedGameSelected) {
string filename = game.Filename;
Debug.Log("opening saved game: " + game);
if(mSaving && (filename == null || filename.Length == 0)) {
filename = "save" + DateTime.Now.ToBinary();
}
if (mSaving) {
slot0.State = "Saving to " + filename;
}
else {
slot0.State = "Loading from " + filename;
}
//open the data.
((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution(filename,
DataSource.ReadCacheOrNetwork,
ConflictResolutionStrategy.UseLongestPlaytime,
SavedGameOpened);
} else {
Debug.LogWarning("Error selecting save game: " + status);
}
}
public void SavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game) {
if(status == SavedGameRequestStatus.Success) {
if( mSaving) {
slot0.State = "Opened, now writing";
byte[] pngData = (mScreenImage!=null) ?mScreenImage.EncodeToPNG():null;
Debug.Log("Saving to " + game);
byte[] data = slot0.ToBytes();
TimeSpan playedTime = slot0.TotalPlayingTime;
SavedGameMetadataUpdate.Builder builder = new
SavedGameMetadataUpdate.Builder()
.WithUpdatedPlayedTime(playedTime)
.WithUpdatedDescription("Saved Game at " + DateTime.Now);
if (pngData != null) {
Debug.Log("Save image of len " + pngData.Length);
builder = builder.WithUpdatedPngCoverImage(pngData);
}
else {
Debug.Log ("No image avail");
}
SavedGameMetadataUpdate updatedMetadata = builder.Build();
((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(game,updatedMetadata,data,SavedGameWritten);
} else {
slot0.State = "Opened, reading...";
((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(game,SavedGameLoaded);
}
} else {
Debug.LogWarning("Error opening game: " + status);
}
}
public void SavedGameLoaded(SavedGameRequestStatus status, byte[] data) {
if (status == SavedGameRequestStatus.Success) {
Debug.Log("SaveGameLoaded, success=" + status);
slot0 = GameData.FromBytes(data);
} else {
Debug.LogWarning("Error reading game: " + status);
}
}
public void SavedGameWritten(SavedGameRequestStatus status, ISavedGameMetadata game) {
if(status == SavedGameRequestStatus.Success) {
Debug.Log ("Game " + game.Description + " written");
slot0.State = "Saved!";
} else {
Debug.LogWarning("Error saving game: " + status);
}
}
public class GameData {
private TimeSpan mPlayingTime;
private DateTime mLoadedTime;
string mData;
string mState;
static readonly string HEADER = "GDv1";
public GameData(string data) {
mData = data;
mState = "Initialized, modified";
mPlayingTime = new TimeSpan();
mLoadedTime = DateTime.Now;
}
public TimeSpan TotalPlayingTime {
get {
TimeSpan delta = DateTime.Now.Subtract(mLoadedTime);
return mPlayingTime.Add(delta);
}
}
public override string ToString () {
string s = HEADER + ":" + mData;
s += ":" + TotalPlayingTime.TotalMilliseconds;
return s;
}
public byte[] ToBytes() {
return System.Text.ASCIIEncoding.Default.GetBytes(ToString());
}
public static GameData FromBytes (byte[] bytes) {
return FromString(System.Text.ASCIIEncoding.Default.GetString(bytes));
}
public static GameData FromString (string s) {
GameData gd = new GameData("initializing from string");
string[] p = s.Split(new char[] { ':' });
if (!p[0].StartsWith(HEADER)) {
Debug.LogError("Failed to parse game data from: " + s);
return gd;
}
gd.mData = p[1];
double val = Double.Parse(p[2]);
gd.mPlayingTime = TimeSpan.FromMilliseconds(val>0f?val:0f);
gd.mLoadedTime = DateTime.Now;
gd.mState = "Loaded successfully";
return gd;
}
public string Data {
get {
return mData;
}
set {
mData = value;
mState += ", modified";
}
}
public string State {
get {
return mState;
}
set {
mState = value;
}
}
}
}

Unity3D IP Camera

I'm using a Marmitek IP RoboCam 641 to import a video feed into unity. I use constantly refreshing snapshots to update a GUI.DrawTexture on the screen. However I recently switched to the Marmitek from a Velleman wireless ip colour camera. Now my snapshot only refreshes once or twice, before stopping and giving this error:
UnityException: Recv failure: Connection was reset
SEMTEX+c__Iterator0.MoveNext () (at Assets/Scripts/SEMTEX.cs:37)
And this is my code:
using UnityEngine;
using System.Collections;
public class SEMTEX : MonoBehaviour {
//public string uri = "http://192.168.1.101/snapshot.cgi";//velleman
public string uri = "http://192.168.1.30/cgi/jpg/image.cgi";//marmitek
public string username = "admin";
public string password = "admin";
int calc = 0;
Texture2D cam;
Texture2D cam2;
public void Start() {
cam=new Texture2D(1, 1, TextureFormat.RGB24, true);
StartCoroutine(Fetch());
cam2=new Texture2D(1, 1, TextureFormat.RGB24, true);
StartCoroutine(Fetch());
}
public IEnumerator Fetch() {
while(true) {
Debug.Log("fetching... "+Time.realtimeSinceStartup);
WWWForm form = new WWWForm();
form.AddField("dummy", "field"); // required by WWWForm
WWW www = new WWW(uri, form.data, new System.Collections.Generic.Dictionary<string,string>() { // using www.headers is depreciated by some odd reason
{"Authorization", "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(username+":"+password))}
});
yield return www;
if(!string.IsNullOrEmpty(www.error))
throw new UnityException(www.error);
www.LoadImageIntoTexture(cam);
www.LoadImageIntoTexture(cam2);
}
}
public void OnGUI() {
GUI.DrawTexture(new Rect(0,0,Screen.width/2,Screen.height), cam);
calc = (Screen.width/2-100);
GUI.DrawTexture(new Rect(calc,0,Screen.width/2,Screen.height), cam2);
Debug.Log (Screen.width);
}
Does anyone have any ideas regarding my error?

Dissapear JButton when click JButton [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I've got an application with some JButtons, if you click them you see a image. Now if you open the frame and you dont have clicked yet you see a image in the middle of the screen. Now i want if you click the JButton for the image, the image is shown and the other image in the middle of the screen is gone but i dont know how to do.
My Frame:
package View;
import java.awt.Color;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import Controller.HomeController;
import Controller.SelectieController;
public class Selectie extends JFrame{
private static String Gregory = "Gregory";
private static String Vermeer = "Vermeer";
private static String Alderweireld = "Alderweireld";
private static String Vertonghen = "Vertonghen";
private static String Anita = "Anita";
private static String Enoh = "Enoh";
private static String Sulejmani = "Sulejmani";
private static String Cristian = "Cristian";
private static String Kolbeinn = "Kolbeinn";
private static String Siem = "Siem";
private static String Lorenzo = "Lorenzo";
private static String Andre = "Andre";
private static String Nicolai = "Nicolai";
private static String Theo = "Theo";
private static String Daley = "Daley";
private static String Nicolas = "Nicolas";
private static String Dmitri = "Dmitri";
private static String Kruis = "Kruis";
private JLabel label, label1, label2;
private JButton keeper, verdediger, verdediger1, verdediger2, verdediger3, verdediger4;
private JButton middenvelder, middenvelder1, aanvaller, aanvaller1, middenvelder2;
private JButton aanvaller2, verdediger5, middenvelder3, verdediger6, middenvelder4;
private JButton aanvaller3, kruis;
private JPanel panel;
private Container window = getContentPane();
public Selectie()
{
initGUI();
}
public void initGUI()
{
setLayout(null);
setTitle();
setSize(800,600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
label = new JLabel();
label.setBounds(0, 0, 266, 800);
label.setBackground(Color.RED);
label.setOpaque(true);
window.add(label);
label1 = new JLabel();
label1.setBounds(266, 0, 266, 800);
label1.setBackground(Color.BLACK);
label1.setOpaque(true);
window.add(label1);
label2 = new JLabel();
label2.setBounds(532, 0, 266, 800);
label2.setBackground(Color.RED);
label2.setOpaque(true);
window.add(label2);
JLabel foto = new JLabel();
label1.add(foto);
kruis = new JButton(new ImageIcon("../Ajax/src/img/logotje.gif"));
kruis.setBorderPainted(false);
kruis.setBounds(40, 150, 188, 188);
kruis.setActionCommand(Kruis);
label1.add(kruis);
keeper = new JButton("1. "+""+" Kenneth Vermeer");
Cursor cur = keeper.getCursor();
keeper.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
keeper.setBounds(20, 50, 186, 12);
keeper.setFocusable(false);
keeper.setBorderPainted(false);
keeper.setContentAreaFilled(false);
keeper.setFont(new Font("Arial",Font.PLAIN,17));
keeper.setForeground(Color.WHITE);
keeper.setActionCommand(Vermeer);
label.add(keeper);
verdediger = new JButton("2. "+""+" Gregory van der Wiel");
Cursor cur1 = verdediger.getCursor();
verdediger.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
verdediger.setBounds(20, 70, 215, 17);
verdediger.setFocusable(false);
verdediger.setBorderPainted(false);
verdediger.setContentAreaFilled(false);
verdediger.setFont(new Font("Arial",Font.PLAIN,17));
verdediger.setForeground(Color.WHITE);
verdediger.setActionCommand(Gregory);
label.add(verdediger);
verdediger1 = new JButton("3. "+""+" Toby Alderweireld");
Cursor cur2 = verdediger1.getCursor();
verdediger1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
verdediger1.setBounds(20, 95, 188, 17);
verdediger1.setFocusable(false);
verdediger1.setBorderPainted(false);
verdediger1.setContentAreaFilled(false);
verdediger1.setFont(new Font("Arial",Font.PLAIN,17));
verdediger1.setForeground(Color.WHITE);
verdediger1.setActionCommand(Alderweireld);
label.add(verdediger1);
verdediger2 = new JButton("4. "+""+" Jan Vertonghen");
Cursor cur3 = verdediger2.getCursor();
verdediger2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
verdediger2.setBounds(20, 120, 174, 17);
verdediger2.setFocusable(false);
verdediger2.setBorderPainted(false);
verdediger2.setContentAreaFilled(false);
verdediger2.setFont(new Font("Arial",Font.PLAIN,17));
verdediger2.setForeground(Color.WHITE);
verdediger2.setActionCommand(Vertonghen);
label.add(verdediger2);
verdediger3 = new JButton("5. "+""+" Vurnon Anita");
Cursor cur4 = verdediger3.getCursor();
verdediger3.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
verdediger3.setBounds(20, 145, 153, 12);
verdediger3.setFocusable(false);
verdediger3.setBorderPainted(false);
verdediger3.setContentAreaFilled(false);
verdediger3.setFont(new Font("Arial",Font.PLAIN,17));
verdediger3.setForeground(Color.WHITE);
verdediger3.setActionCommand(Anita);
label.add(verdediger3);
middenvelder = new JButton("6. "+""+" Eyong Enoh");
Cursor cur5 = middenvelder.getCursor();
middenvelder.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
middenvelder.setBounds(20, 170, 148, 17);
middenvelder.setFocusable(false);
middenvelder.setBorderPainted(false);
middenvelder.setContentAreaFilled(false);
middenvelder.setFont(new Font("Arial",Font.PLAIN,17));
middenvelder.setForeground(Color.WHITE);
middenvelder.setActionCommand(Enoh);
label.add(middenvelder);
aanvaller = new JButton("7. "+""+" Miralem Sulejmani");
Cursor cur6 = aanvaller.getCursor();
aanvaller.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
aanvaller.setBounds(20, 195, 190, 17);
aanvaller.setFocusable(false);
aanvaller.setBorderPainted(false);
aanvaller.setContentAreaFilled(false);
aanvaller.setFont(new Font("Arial",Font.PLAIN,17));
aanvaller.setForeground(Color.WHITE);
aanvaller.setActionCommand(Sulejmani);
label.add(aanvaller);
middenvelder1 = new JButton("8. "+""+" Cristian Eriksen");
Cursor cur7 = middenvelder1.getCursor();
middenvelder1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
middenvelder1.setBounds(20, 220, 174, 12);
middenvelder1.setFocusable(false);
middenvelder1.setBorderPainted(false);
middenvelder1.setContentAreaFilled(false);
middenvelder1.setFont(new Font("Arial",Font.PLAIN,17));
middenvelder1.setForeground(Color.WHITE);
middenvelder1.setActionCommand(Cristian);
label.add(middenvelder1);
aanvaller1 = new JButton("9. "+""+" Kolbeinn Sightórsson");
Cursor cur8 = aanvaller1.getCursor();
aanvaller1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
aanvaller1.setBounds(20, 245, 212, 17);
aanvaller1.setFocusable(false);
aanvaller1.setBorderPainted(false);
aanvaller1.setContentAreaFilled(false);
aanvaller1.setFont(new Font("Arial",Font.PLAIN,17));
aanvaller1.setForeground(Color.WHITE);
aanvaller1.setActionCommand(Kolbeinn);
label.add(aanvaller1);
middenvelder2 = new JButton("10. "+""+" Siem de Jong");
Cursor cur9 = middenvelder2.getCursor();
middenvelder2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
middenvelder2.setBounds(20, 270, 168, 17);
middenvelder2.setFocusable(false);
middenvelder2.setBorderPainted(false);
middenvelder2.setContentAreaFilled(false);
middenvelder2.setFont(new Font("Arial",Font.PLAIN,17));
middenvelder2.setForeground(Color.WHITE);
middenvelder2.setActionCommand(Siem);
label.add(middenvelder2);
aanvaller2 = new JButton("11. "+""+" Lorenzo Ebecilio");
Cursor cur10 = aanvaller2.getCursor();
aanvaller2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
aanvaller2.setBounds(20, 295, 189, 12);
aanvaller2.setFocusable(false);
aanvaller2.setBorderPainted(false);
aanvaller2.setContentAreaFilled(false);
aanvaller2.setFont(new Font("Arial",Font.PLAIN,17));
aanvaller2.setForeground(Color.WHITE);
aanvaller2.setActionCommand(Lorenzo);
label.add(aanvaller2);
verdediger4 = new JButton("13. "+""+" André Ooijer");
Cursor cur11 = verdediger4.getCursor();
verdediger4.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
verdediger4.setBounds(20, 320, 159, 17);
verdediger4.setFocusable(false);
verdediger4.setBorderPainted(false);
verdediger4.setContentAreaFilled(false);
verdediger4.setFont(new Font("Arial",Font.PLAIN,17));
verdediger4.setForeground(Color.WHITE);
verdediger4.setActionCommand(Andre);
label.add(verdediger4);
verdediger5 = new JButton("15. "+""+" Nicolai Boilesen");
Cursor cur12 = verdediger5.getCursor();
verdediger5.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
verdediger5.setBounds(20, 345, 183, 12);
verdediger5.setFocusable(false);
verdediger5.setBorderPainted(false);
verdediger5.setContentAreaFilled(false);
verdediger5.setFont(new Font("Arial",Font.PLAIN,17));
verdediger5.setForeground(Color.WHITE);
verdediger5.setActionCommand(Nicolai);
label.add(verdediger5);
middenvelder3 = new JButton("16. "+""+" Theo Janssen");
Cursor cur13 = middenvelder3.getCursor();
middenvelder3.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
middenvelder3.setBounds(20, 370, 169, 12);
middenvelder3.setFocusable(false);
middenvelder3.setBorderPainted(false);
middenvelder3.setContentAreaFilled(false);
middenvelder3.setFont(new Font("Arial",Font.PLAIN,17));
middenvelder3.setForeground(Color.WHITE);
middenvelder3.setActionCommand(Theo);
label.add(middenvelder3);
verdediger6 = new JButton("17. "+""+" Daley Blind");
Cursor cur14 = verdediger6.getCursor();
verdediger6.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
verdediger6.setBounds(20, 395, 150, 17);
verdediger6.setFocusable(false);
verdediger6.setBorderPainted(false);
verdediger6.setContentAreaFilled(false);
verdediger6.setFont(new Font("Arial",Font.PLAIN,17));
verdediger6.setForeground(Color.WHITE);
verdediger6.setActionCommand(Daley);
label.add(verdediger6);
middenvelder4 = new JButton("18. "+""+" Nicolás Lodeiro");
Cursor cur15 = middenvelder4.getCursor();
middenvelder4.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
middenvelder4.setBounds(20, 420, 180, 12);
middenvelder4.setFocusable(false);
middenvelder4.setBorderPainted(false);
middenvelder4.setContentAreaFilled(false);
middenvelder4.setFont(new Font("Arial",Font.PLAIN,17));
middenvelder4.setForeground(Color.WHITE);
middenvelder4.setActionCommand(Nicolas);
label.add(middenvelder4);
aanvaller3 = new JButton("19. "+""+" Dmitri Bulykin");
Cursor cur16 = aanvaller3.getCursor();
aanvaller3.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
aanvaller3.setBounds(20, 445, 168, 17);
aanvaller3.setFocusable(false);
aanvaller3.setBorderPainted(false);
aanvaller3.setContentAreaFilled(false);
aanvaller3.setFont(new Font("Arial",Font.PLAIN,17));
aanvaller3.setForeground(Color.WHITE);
aanvaller3.setActionCommand(Dmitri);
label.add(aanvaller3);
SelectieController s1 = new SelectieController(keeper, foto, verdediger, verdediger1, verdediger2,
verdediger3, middenvelder, aanvaller, middenvelder1, aanvaller1, middenvelder2, aanvaller2,
verdediger4, verdediger5, middenvelder3, verdediger6, middenvelder4, aanvaller3, kruis);
keeper.addActionListener(s1);
verdediger.addActionListener(s1);
verdediger1.addActionListener(s1);
verdediger2.addActionListener(s1);
verdediger3.addActionListener(s1);
verdediger4.addActionListener(s1);
verdediger5.addActionListener(s1);
verdediger6.addActionListener(s1);
middenvelder.addActionListener(s1);
aanvaller.addActionListener(s1);
middenvelder1.addActionListener(s1);
aanvaller1.addActionListener(s1);
middenvelder2.addActionListener(s1);
aanvaller2.addActionListener(s1);
middenvelder3.addActionListener(s1);
middenvelder4.addActionListener(s1);
aanvaller3.addActionListener(s1);
}
}
Kruis is the image in the midd of the screen a=
ActionPerformed class:
package Controller;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class SelectieController implements ActionListener {
private JButton keeper, verdediger, verdediger1, verdediger2, verdediger3;
private JButton middenvelder, aanvaller, middenvelder1, aanvaller1, middenvelder2;
private JButton aanvaller2, verdediger4, verdediger5, middenvelder3, verdediger6;
private JButton middenvelder4, aanvaller3, kruis;
private ImageIcon imageIcon, imageIcon1, imageIcon2, imageIcon3, imageIcon4, imageIcon5;
private ImageIcon imageIcon6, imageIcon7, imageIcon8, imageIcon9, imageIcon10, imageIcon11;
private ImageIcon imageIcon12, imageIcon13, imageIcon14, imageIcon15, imageIcon16;
private JLabel imageLabel;
private Image image, image1, image2, image3, image4, image5, image6, image7, image8, image9;
private Image image10, image11, image12, image13, image14, image15, image16;
private static String Vermeer = "Vermeer";
private static String Gregory = "Gregory";
private static String Alderweireld = "Alderweireld";
private static String Vertonghen = "Vertonghen";
private static String Anita = "Anita";
private static String Enoh = "Enoh";
private static String Sulejmani = "Sulejmani";
private static String Cristian = "Cristian";
private static String Kolbeinn = "Kolbeinn";
private static String Siem = "Siem";
private static String Lorenzo = "Lorenzo";
private static String Andre = "Andre";
private static String Nicolai = "Nicolai";
private static String Theo = "Theo";
private static String Daley = "Daley";
private static String Nicolas = "Nicolas";
private static String Dmitri = "Dmitri";
private static String Kruis = "Kruis";
public SelectieController(JButton vermeer, JLabel vermeer1, JButton gregory, JButton toby, JButton jan,
JButton vurnon, JButton eyong, JButton sulejmani, JButton cristian, JButton kolbeinn, JButton siem,
JButton lorenzo, JButton andre, JButton nicolai, JButton theo, JButton daley, JButton nicolas,
JButton dmitri, JButton kruis)
{
kruis = kruis;
keeper = vermeer;
verdediger1 = toby;
verdediger = gregory;
verdediger2 = jan;
verdediger3 = vurnon;
middenvelder = eyong;
aanvaller = sulejmani;
aanvaller1 = kolbeinn;
middenvelder1 = cristian;
imageLabel = vermeer1;
middenvelder2 = siem;
aanvaller2 = lorenzo;
verdediger4 = andre;
verdediger5 = nicolai;
middenvelder3 = theo;
verdediger6 = daley;
middenvelder4 = nicolas;
aanvaller3 = dmitri;
//Kenneth Vermeer
try
{
image = ImageIO.read(getClass().getResource("/img/kenneth.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon = new ImageIcon(image);
}{
// Gregory van der Wiel
try
{
image1 = ImageIO.read(getClass().getResource("/img/wiel.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon1 = new ImageIcon(image1);
}{
// Toby Alderweireld
try
{
image2 = ImageIO.read(getClass().getResource("/img/toby.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon2 = new ImageIcon(image2);
}{
// Jan Vertonghen
try
{
image3 = ImageIO.read(getClass().getResource("/img/jan.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon3 = new ImageIcon(image3);
}{
// Vurnon anita
try
{
image4 = ImageIO.read(getClass().getResource("/img/vurnon.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon4 = new ImageIcon(image4);
}{
// Eyong Enoh
try
{
image5 = ImageIO.read(getClass().getResource("/img/eyong.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon5 = new ImageIcon(image5);
}{
// Miralem Sulejmani
try
{
image6 = ImageIO.read(getClass().getResource("/img/sulejmani.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon6 = new ImageIcon(image6);
}{
// Cristian Eriksen
try
{
image7 = ImageIO.read(getClass().getResource("/img/eriksen.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon7 = new ImageIcon(image7);
}{
// Kolbeinn sightorsson
try
{
image8 = ImageIO.read(getClass().getResource("/img/kolbeinn.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon8 = new ImageIcon(image8);
}{
// Siem de Jong
try
{
image9 = ImageIO.read(getClass().getResource("/img/siem.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon9 = new ImageIcon(image9);
}{
// Lorenzo Ebecilio
try
{
image10 = ImageIO.read(getClass().getResource("/img/lorenzo.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon10 = new ImageIcon(image10);
}{
// Andre Ooijer
try
{
image11 = ImageIO.read(getClass().getResource("/img/andre.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon11 = new ImageIcon(image11);
}{
// Nicolai Boilesen
try
{
image12 = ImageIO.read(getClass().getResource("/img/nicolai.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon12 = new ImageIcon(image12);
}{
// Theo Janssen
try
{
image13 = ImageIO.read(getClass().getResource("/img/theo.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon13 = new ImageIcon(image13);
}{
// Daley Blind
try
{
image14 = ImageIO.read(getClass().getResource("/img/daley.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon14 = new ImageIcon(image14);
}{
// Nicolas Lodeiro
try
{
image15 = ImageIO.read(getClass().getResource("/img/nicolas.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon15 = new ImageIcon(image15);
}{
// Dmitri Bulykin
try
{
image16 = ImageIO.read(getClass().getResource("/img/dmitri.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
imageIcon16 = new ImageIcon(image16);
}
public void actionPerformed(ActionEvent event)
{
String actionCommand = event.getActionCommand();
// Kenneth Vermeer
if (Vermeer.equals(actionCommand))
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
imageLabel.setIcon(imageIcon );
imageLabel.setBounds(75, 50, 120, 150);
kruis.setVisible(false);
}
});
}
// Gregory van der Wiel
if (Gregory.equals(actionCommand))
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
imageLabel.setIcon(imageIcon1 );
imageLabel.setBounds(75, 50, 120, 150);
}
});
}
// Toby Alderweireld
if (Alderweireld.equals(actionCommand))
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
imageLabel.setIcon(imageIcon2 );
imageLabel.setBounds(75, 50, 120, 150);
}
});
}
// Jan Vertonghen
if (Vertonghen.equals(actionCommand))
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
imageLabel.setIcon(imageIcon3 );
imageLabel.setBounds(75, 50, 120, 150);
}
});
}
//Vurnon Anita
if (Anita.equals(actionCommand))
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
imageLabel.setIcon(imageIcon4 );
imageLabel.setBounds(75, 50, 120, 150);
}
});
}
// Eyong Enoh
if (Enoh.equals(actionCommand))
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
imageLabel.setIcon(imageIcon5 );
imageLabel.setBounds(75, 50, 120, 150);
}
});
}
// Miralem Sulejmani
if (Sulejmani.equals(actionCommand))
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
imageLabel.setIcon(imageIcon6 );
imageLabel.setBounds(75, 50, 120, 150);
}
});
}
}}
First, whenever you have elements with names like button1, button2 etc. you need to refactor the code and work with an array instead. This way you can refer to the needed element using its index, instead of many if-else statements. That's applies for the Strings , Buttons, Images and ImageIcons.
Now, when a button is pressed, find it's index (in a loop for example) and make all other button/images disappear, using setVisible(false), and only the relevant image display using setVisible(true).