Using a external Spinner control in Windows Mobile 6.0 - windows-mobile-6

I am using slideUI controls in my project . There is a spinner control which is used as wait cursor. I want to display the spinner when I load data in a List.
But when I try to display the spinner it visualize as an image not a rotating image.
Below is my code.
private void uiButton_Click(object sender, EventArgs e)
{
ShowFrame(this.uiPanel1);
Application.DoEvents();
LoadList();
HideFrame(uiPanel1);
}
private void LoadList()
{
try
{
//Call the BeginAddControls before starting manipulations with UIList
uiList1.BeginAddControls();
for (int i = 0; i < 100; i++)
{
UIListItem item = new UIListItem();
item.Text = "Primary Text" + i;
item.SecondaryText = "This is secondary text..";
item.ItemStyle = UIListItemStyle.SingleText;
item.Height = Utils.CalcScaleSize(38);
item.BackColor = System.Drawing.SystemColors.Window;
item.BackEndColorSelected = System.Drawing.SystemColors.Highlight;
item.BackStartColorSelected = System.Drawing.SystemColors.Highlight;
item.BottomBorderColor = System.Drawing.Color.Gainsboro;
item.Buffering = true;
item.ColorScheme = SlideUI.UIColorSchemesCustom.Orange;
item.Dock = System.Windows.Forms.DockStyle.Top;
item.GroupArrowColor = System.Drawing.Color.Gray;
item.GroupArrowColorSelected = System.Drawing.Color.White;
item.IconQVGA = null;
item.IconSize = new System.Drawing.Size(25, 31);
item.IconTransparent = false;
item.IconTransparentColor = System.Drawing.Color.Transparent;
item.IconVGA = null;
item.IconVisible = true;
item.InheritParentSettings = true;
item.IsGroup = false;
item.IsSelected = false;
item.SecondaryTextColor = System.Drawing.SystemColors.GrayText;
item.SecondaryTextColorSelected = System.Drawing.SystemColors.HighlightText;
item.SecondaryTextFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Regular);
item.TextColor = System.Drawing.SystemColors.WindowText;
item.TextColorSelected = System.Drawing.SystemColors.HighlightText;
item.TextFont = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold);
item.UseGradient = true;
item.VirtualBufferRendered = false;
uiList1.AddControl(item);
}
//Call of EndAddControls method when the UIListItems binding is done
uiList1.EndAddControls();
//HideFrame(uiPanel1);
//ShowFrame(this.panel1, "Panel1");
}
catch (Exception ex)
{
UIMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK,
UIMessageIcons.Done, UIColorSchemesCustom.Orange);
}
}
private void ShowFrame(Panel panel)
{
Panel pnlPanel = new Panel();
pnlPanel = panel;
//pnlPanel.Location = new System.Drawing.Point(0, 0);
pnlPanel.Show();
pnlPanel.BringToFront();
}
private void HideFrame(Panel panel)
{
Panel pnlPanel = new Panel();
pnlPanel = panel;
pnlPanel.Hide();
}
Thanks in advance

Related

change pdf image background using Itextsharp

I am trying to change background color of all images of pdf using Itextshap.
How can i loop through all images and change background color of the images
I used below code to extract pdf images
public static void ExtractImagesFromPDF(string sourcePdf, string outputPath)
{
// NOTE: This will only get the first image it finds per page.
PdfReader pdf = new PdfReader(sourcePdf);
RandomAccessFileOrArray raf = new iTextSharp.text.pdf.RandomAccessFileOrArray(sourcePdf);
try
{
for (int pageNumber = 1; pageNumber <= pdf.NumberOfPages; pageNumber++)
{
PdfDictionary pg = pdf.GetPageN(pageNumber);
// recursively search pages, forms and groups for images.
PdfObject obj = FindImageInPDFDictionary(pg);
if (obj != null)
{
int XrefIndex = Convert.ToInt32(((PRIndirectReference)obj).Number.ToString(System.Globalization.CultureInfo.InvariantCulture));
PdfObject pdfObj = pdf.GetPdfObject(XrefIndex);
PdfStream pdfStrem = (PdfStream)pdfObj;
byte[] bytes = PdfReader.GetStreamBytesRaw((PRStream)pdfStrem);
if ((bytes != null))
{
using (System.IO.MemoryStream memStream = new System.IO.MemoryStream(bytes))
{
memStream.Position = 0;
System.Drawing.Image img = System.Drawing.Image.FromStream(memStream);
// must save the file while stream is open.
if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);
string path = Path.Combine(outputPath, String.Format(#"{0}.jpg", pageNumber));
System.Drawing.Imaging.EncoderParameters parms = new System.Drawing.Imaging.EncoderParameters(1);
parms.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Compression, 0);
System.Drawing.Imaging.ImageCodecInfo jpegEncoder = Utilities.GetImageEncoder("JPEG");
img.Save(path, jpegEncoder, parms);
}
}
}
}
}
catch
{
throw;
}
finally
{
pdf.Close();
raf.Close();
}
}
private static PdfObject FindImageInPDFDictionary(PdfDictionary pg)
{
PdfDictionary res =
(PdfDictionary)PdfReader.GetPdfObject(pg.Get(PdfName.RESOURCES));
PdfDictionary xobj =
(PdfDictionary)PdfReader.GetPdfObject(res.Get(PdfName.XOBJECT));
if (xobj != null)
{
foreach (PdfName name in xobj.Keys)
{
PdfObject obj = xobj.Get(name);
if (obj.IsIndirect())
{
PdfDictionary tg = (PdfDictionary)PdfReader.GetPdfObject(obj);
PdfName type =
(PdfName)PdfReader.GetPdfObject(tg.Get(PdfName.SUBTYPE));
//image at the root of the pdf
if (PdfName.IMAGE.Equals(type))
{
return obj;
}// image inside a form
else if (PdfName.FORM.Equals(type))
{
return FindImageInPDFDictionary(tg);
} //image inside a group
else if (PdfName.GROUP.Equals(type))
{
return FindImageInPDFDictionary(tg);
}
}
}
}
return null;
}
Many thanks in advance

UI Freeze in SWT

I am new to SWT. I am trying to create a small application. Basically it has two screens. In the first screen I have to take user credentials. It has to be validated. If its successful I have to query a table and build a tree structure. Both validation and building the tree freezes my UI. I searched stackoverflow and google. I got the below options.
Display.getDefault().asyncExec() and starting long running process as separate thread from UI thread.
But still my UI freezes.
When the user clicks on Logon button. I created a thread. As a first step I tried to show a indefinite progress bar using asyncExec. Since I have to access the Uname and Password I have to trigger another asyncexec and perform the login. If its successful populated the tree.
I triggered another asyncExec to close the progress bar.
My UI freezes from Logon click till Tree population completion. Where am I going wrong.
new Thread(new Runnable()
{
private int progress = 0;
private static final int INCREMENT = 10;
#Override
public void run()
{
while (!progressBar.isDisposed())
{
Display.getDefault().asyncExec(new Runnable()
{
#Override
public void run()
{
if (!progressBar.isDisposed())
progressBar.setVisible(true);
}
});
Display.getDefault().asyncExec(new Runnable()
{
#Override
public void run()
{
String sAuth = null;
switch(tAuth.getText()){
case "Enterprise": sAuth = "secEnterprise"; break;
case "LDAP": sAuth = "secLDAP"; break;
case "Windows AD": sAuth = "secWinAD"; break;
case "SAP": sAuth = "secSAPR3"; break;
}
try {
log.info("Attempting to create enterprise session");
CoreLogic.logonEnterprise(tUSR.getText().trim(),tPWD.getText().trim(),sAuth,tCMS.getText());
if(CommonVariables.entsession){
log.info("Enterprise session created.");
CoreLogic.getUniverse();
log.info("Populating universe tree");
String[] temp;
for (Entry<Integer, UnvObj> entry : CommonVariables.unvlst.entrySet()) {
UnvObj t = entry.getValue();
temp = t.getPath().split("/");
if (temp[0].equals("Universes")){
int max = temp.length;
int i =0 ;
boolean flag = false;
TreeItem trItem = null;
do{
if(i == 0) {
if(tree.getItemCount() == 0){
flag = false;
}
else
{
for(int k = 0; k < tree.getItemCount(); k++){
if(temp[i].equals(tree.getItem(k).getText())){
i++;
trItem = tree.getItem(k);
flag =true;
break;
}
else
{
flag = false;
}
}
}
}
else{
if(trItem.getItemCount() == 0){
flag = false;
}
else
{
for(int k = 0; k < trItem.getItemCount(); k++){
if(temp[i].equals(trItem.getItem(k).getText())){
i++;
trItem = trItem.getItem(k);
flag =true;
break;
}
else
{
flag = false;
}
}
}
}
}while (flag == true && i < max);
TreeItem Item = null;
if (i == 0){
for (int k = 0; k < max; k++){
if(k == 0) {
Item = new TreeItem(tree,SWT.NONE);
Item.setText(temp[k]);
Item.setData("Type","Folder");
Image image = new Image(display,ResourceLoader.load("/images/Fld.png"));
Item.setImage(image);
}else
{
Item = new TreeItem(Item,SWT.NONE);
Item.setText(temp[k]);
Item.setData("Type","Folder");
Image image = new Image(display,ResourceLoader.load("/images/Fld.png"));
Item.setImage(image);
}
}
} else if( i < max){
for (int k = i; k < max; k++){
trItem = new TreeItem(trItem,SWT.NONE);
trItem.setText(temp[k]);
trItem.setData("Type","Folder");
Image image = new Image(display,ResourceLoader.load("/images/Fld.png"));
trItem.setImage(image);
}
}
if (i == 0){
Item = new TreeItem(Item,SWT.NONE);
Item.setText(t.getName());
Item.setData("Type",t.getKind());
Item.setData("Mapkey",entry.getKey());
if(t.getKind().equals("Universe")){
Image image = new Image(display,ResourceLoader.load("/images/Unv.ico"));
Item.setImage(image);
}
else{
Image image = new Image(display,ResourceLoader.load("/images/Unx.ico"));
Item.setImage(image);
}
} else
{
trItem = new TreeItem(trItem,SWT.NONE);
trItem.setText(t.getName());
trItem.setData("Type",t.getKind());
trItem.setData("Mapkey",entry.getKey());
if(t.getKind().equals("Universe")){
Image image = new Image(display,ResourceLoader.load("/images/Unv.ico"));
trItem.setImage(image);
}
else{
Image image = new Image(display,ResourceLoader.load("/images/Unx.ico"));
trItem.setImage(image);
}
}
}
}
log.info("Universe Tree Populated.");
sl.topControl =Universe;
Main.layout();
}else
{
log.info("Unable to create enterprise session");
MessageBox messageBox = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
messageBox.setText("Report Extractor");
messageBox.setMessage("Unable to create the enterprise session with the provided credentials. Please verify it.");
messageBox.open();
}
}
catch(Exception exp)
{
log.error("Fail to create enterprise session",exp);
}
}
});
Display.getDefault().asyncExec(new Runnable()
{
#Override
public void run()
{
if (!progressBar.isDisposed())
progressBar.setVisible(false);
}
});
}
}
}).start();

How to resize layout containers when the parent window resizes?

I am developing a music player application in Vala 0.14. The main toolbar of this application contains nested Box Layouts and all of them have the hexpand property set to true.
While packing the widgets/layouts I made sure that the expand and fill arguments were true, however the toolbar fails to resize when the size of parent window changes.
Here are the screenshots.
[NORMAL]
[RESIZE -- SIZE INCREASED]
[RESIZE -- SIZE DECREASED]
Is it enough to set the hexpand property to true or do I need to make some adjustments to the box layouts when the parent window's size_allocate signal is emitted ?
CODE:
using Gtk;
namespace Conjure.Widget
{
public class MainToolBar : Object
{
/* Declare reference variables */
private Toolbar tlbMain;
private ToolItem tiMain;
public Scale sclProgress;
private Label lblSongName;
private Label lblArtistName;
private Label lblAlbumName;
private Box hboxMain;
private Box vboxControls;
private Box hboxControls;
private Box hboxButtons;
private Box hboxMetaData;
private Box vboxMetaData;
private Box vboxPreferences;
private Box hboxPreferences;
private Image imgArt;
private Image icnPrevious;
public Image icnPlay;
public Image icnPause;
private Image icnNext;
private Image icnRepeat;
private Image icnVolume;
private Image icnPhone;
private Image icnSuperMenu;
private Image icnEqualizer;
public Button btnPrevious;
public Button btnTogglePlay;
public Button btnNext;
public Button btnVolume;
public Button btnSuperMenu;
public Button btnEqualizer;
private ToggleButton btnPhone;
private ToggleButton btnRepeat;
private Separator sep1;
private Separator sep2;
construct
{
/* Create the parent box */
hboxMain = new Box(Orientation.HORIZONTAL, 0);
hboxMain.hexpand = true;
hboxMain.homogeneous = true; //
/* Create boxes to hold meta data */
hboxMetaData = new Box(Orientation.HORIZONTAL, 5);
vboxMetaData = new Box(Orientation.VERTICAL, 0);
vboxMetaData.homogeneous = true;
hboxMetaData.hexpand = true;
vboxMetaData.hexpand = true;
/* Create boxes for control elements */
vboxControls = new Box(Orientation.VERTICAL, 0);
hboxControls = new Box(Orientation.HORIZONTAL, 0);
hboxButtons = new Box(Orientation.HORIZONTAL, 0);
vboxControls.homogeneous = true;
vboxControls.hexpand = true;
hboxButtons.homogeneous = false;
hboxButtons.hexpand = true;
hboxButtons.halign = Align.CENTER;
hboxControls.hexpand = true;
/* Create boxes for preference control */
vboxPreferences = new Box(Orientation.VERTICAL, 0);
hboxPreferences = new Box(Orientation.HORIZONTAL, 0);
vboxPreferences.hexpand = true;
hboxPreferences.hexpand = true;
/* Create and load image mockup */
imgArt = new Image();
//imgArt.set_from_file("/home/utsav/jmrfs.png");
imgArt.halign = Align.START;
/* Make labels for meta data */
lblSongName = new Label(null);
lblArtistName = new Label(null);
lblAlbumName = new Label(null);
lblSongName.set_markup_with_mnemonic("<b>Down</b>");
lblArtistName.set_markup_with_mnemonic("Jay Sean ft. Lil' Wayne");
lblAlbumName.set_markup_with_mnemonic("All or Nothing");
lblSongName.halign = Align.START;
lblArtistName.halign = Align.START;
lblAlbumName.halign = Align.START;
lblSongName.hexpand = true;
lblAlbumName.hexpand = true;
lblArtistName.hexpand = true;
/* Create audio progress bar */
sclProgress = new Scale(Gtk.Orientation.HORIZONTAL, new Adjustment(0.0, 0.0, 10.0, 0.1, 1.0, 1.0));
sclProgress.draw_value = false;
sclProgress.width_request = 300;
// Stylize control
/*StyleContext style_context = sclProgress.get_style_context();
CssProvider css_provider = new CssProvider();
try
{
css_provider.load_from_path(Conjure.Utility.path_to_assets () + "/css/style.css");
}
catch(Error e)
{
stderr.puts("Unable to load specified style sheet.");
}
style_context.add_provider(css_provider, STYLE_PROVIDER_PRIORITY_THEME);*/
/* Create toolbar buttons */
btnPrevious = new Button();
btnTogglePlay = new Button();
btnNext = new Button();
btnVolume = new Button();
btnSuperMenu = new Button();
btnEqualizer = new Button();
btnRepeat = new ToggleButton();
btnPhone = new ToggleButton();
btnPrevious.hexpand = false;
icnPrevious = new Image();
icnPause = new Image();
icnPlay = new Image();
icnNext = new Image();
icnPhone = new Image();
icnRepeat = new Image();
icnVolume = new Image();
icnSuperMenu = new Image();
icnEqualizer = new Image();
/*icnPrevious.set_from_file(Conjure.Utility.path_to_assets () + "/icons/media-skip-backward.png");
icnPlay.set_from_file(Conjure.Utility.path_to_assets () + "/icons/media-playback-start.png");
icnPause.set_from_file(Conjure.Utility.path_to_assets () + "/icons/media-playback-pause.png");
icnNext.set_from_file(Conjure.Utility.path_to_assets () + "/icons/media-skip-forward.png");
icnPhone.set_from_file(Conjure.Utility.path_to_assets () + "/icons/phone.png");
icnRepeat.set_from_file(Conjure.Utility.path_to_assets () + "/icons/media-playlist-repeat.png");
icnVolume.set_from_file(Conjure.Utility.path_to_assets () + "/icons/audio-volume-high.png");
icnSuperMenu.set_from_file(Conjure.Utility.path_to_assets () + "/icons/document-properties.png");
icnEqualizer.set_from_file(Conjure.Utility.path_to_assets () + "/icons/media-graphic-equalizer.png");
btnPrevious.image = icnPrevious;
btnNext.image = icnNext;
btnTogglePlay.image = icnPlay;
btnPhone.image = icnPhone;
btnRepeat.image = icnRepeat;
btnVolume.image = icnVolume;
btnSuperMenu.image = icnSuperMenu;
btnEqualizer.image = icnEqualizer;*/
sep1 = new Separator(Orientation.VERTICAL);
sep2 = new Separator(Orientation.VERTICAL);
/* Start packing widgets */
// Pack Meta Data Box
vboxMetaData.pack_start(lblSongName, true, true, 0);
vboxMetaData.pack_start(lblAlbumName, true, true, 0);
vboxMetaData.pack_start(lblArtistName, true, true, 0);
hboxMetaData.pack_start(imgArt, false, true, 0);
hboxMetaData.pack_start(vboxMetaData, true, true, 0);
// Pack controls box
vboxControls.pack_start(sclProgress, true, true, 0);
hboxButtons.pack_start(btnPrevious, false, false, 0);
hboxButtons.pack_start(btnTogglePlay, false, false, 0);
hboxButtons.pack_start(btnNext, false, false, 0);
hboxButtons.pack_start(sep1, false, false, 0);
hboxButtons.pack_start(btnRepeat, false, false, 0);
hboxButtons.pack_start(btnVolume, false, false, 0);
hboxButtons.pack_start(sep2, false, false, 0);
hboxButtons.pack_start(btnPhone, false, false, 0);
vboxControls.pack_start(hboxButtons, true, true, 0);
// Pack preference box
hboxPreferences.pack_end(btnSuperMenu, false, false, 0);
hboxPreferences.pack_end(btnEqualizer, false, false, 0);
vboxPreferences.pack_end(hboxPreferences, false, false, 0);
vboxPreferences.halign = Align.END;
// Pack main box
hboxMain.pack_start(hboxMetaData, true, true, 0);
hboxMain.pack_start(vboxControls, true, true, 0);
hboxMain.pack_start(vboxPreferences, true, true, 0);
/* Create ToolItem */
tiMain = new ToolItem();
tiMain.add(hboxMain);
tiMain.hexpand = true;
/* Create Toolbar */
tlbMain = new Toolbar();
tlbMain.add(tiMain);
tlbMain.hexpand = true;
tlbMain.vexpand = false;
}
public void resize_main_layout()
{
}
public Gtk.Widget toolbar
{
get
{
return tlbMain;
}
}
}
}
[Main Module]
using Gtk;
using Conjure.Widget;
namespace Conjure.App
{
public class MainWindow : Window
{
private Box vboxMain;
private Box hboxPlaylists;
private MainToolBar maintoolbar;
/*private Conjure.Library.MusicPlayer player;
private SyncThread t;
public Cancellable c;
private unowned Thread<void*> t_a;
// dummy variable
bool track_selected;*/
construct
{
this.title = "Conjure";
this.set_default_size(905, 600);
this.window_position = WindowPosition.CENTER;
//t = null;
//c = null;
//track_selected = true;
vboxMain = new Box(Orientation.VERTICAL, 0);
hboxPlaylists = new Box(Orientation.HORIZONTAL, 0);
maintoolbar = new MainToolBar();
//player = Conjure.Library.MusicPlayer.get();
vboxMain.homogeneous = false;
vboxMain.pack_start(maintoolbar.toolbar, false, true, 0);
//maintoolbar.btnTogglePlay.clicked.connect(toggle_play_clicked);
maintoolbar.sclProgress.set_state (Gtk.StateType.INSENSITIVE);
/*player.state_changed.connect(() =>
{
if(player.get_state() == Conjure.Library.States.READY)
{
track_selected = true;
update_metaphors ();
}
});*/
/*maintoolbar.sclProgress.change_value.connect((s, d) =>
{
stderr.printf("Moved\n");
player.toggle_play ();
player.seek_player((int64) d);
player.toggle_play ();
});
this.size_allocate.connect((allocation) =>
{
stderr.printf("Resized\n");
maintoolbar.resize_main_layout ();
vboxMain.resize_children ();
});*/
vboxMain.hexpand = true;
add(vboxMain);
}
/*void toggle_play_clicked(Gtk.Widget w)
{
w.set_sensitive (false);
if (new_track_selected () && player.get_state() != Conjure.Library.States.PLAYING)
{
stderr.puts("A\n");
kill_thread ();
player.set_track("/home/utsav/abc.mp3");
player.toggle_play ();
make_and_run_thread ();
}
else if (player.get_state() == Conjure.Library.States.PLAYING)
{
stderr.puts("B\n");
kill_thread ();
player.toggle_play ();
}
else if (!(new_track_selected ()) && player.get_state() == Conjure.Library.States.PAUSED)
{
stderr.puts("C\n");
player.toggle_play();
make_and_run_thread ();
}
update_metaphors ();
w.set_sensitive (true);
}*/
/*bool new_track_selected()
{
// method stub
bool p;
p = track_selected;
track_selected = false;
return p;
}*/
/*void kill_thread ()
{
try
{
if(c!=null)
{
c.cancel ();
t_a.join();
}
}
catch(ThreadError err)
{
stderr.printf ("Error: %s", err.message);
}
}
void make_and_run_thread()
{
try
{
c = new Cancellable();
t = new SyncThread(maintoolbar.sclProgress, player.audio_player (), c);
t_a = Thread.create<void*> (t.thread_func, true);
}
catch(ThreadError err)
{
stderr.printf ("Error: %s", err.message);
}
}*/
/*void update_metaphors()
{
if(player.get_state()== Conjure.Library.States.PLAYING)
{
maintoolbar.btnTogglePlay.image = maintoolbar.icnPause;
}
else
{
maintoolbar.btnTogglePlay.image = maintoolbar.icnPlay;
}
}*/
}
}
Without seeing the code it's hard to tell for sure, but my guess is that it does expand. Assuming you have a horizontal box with three children (one for each section) you probably want to set only the middle child to expand. Right now, that third child is also expanding and allocating whitespace.
My advice is to try to create your UI in Glade first. Even if you don't want to use Glade for the final product, it makes it easy to see what different configurations do and will make diagnosing issues like this much easier.

Java - I think my boolean is defaulting to true for some reason

I'm having an issue with my hangman program. When I run it, the label holding the int variable "lives" is supposed to update when you guess a wrong letter. But for some reason it isn't. I've placed this in my code as a test mechanism, and it isn't appearing even here.
if (used[letter] = false) {
System.out.println("test");
However, when I place it here.. It DOES work..
if (finished == false) {
boolean found = false;
boolean www = false;
System.out.println("test");
if (used[letter] = false) {
It almost leads me to believe that used[letter] is true by default, when it really shouldn't be. The variable is declared at the very top. Any thoughts?
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.util.ArrayList;
public class Hangman implements ActionListener {
JFrame frame;
JPanel stats = new JPanel();
JLabel currentWordLA = new JLabel("Current word:");
JLabel triedLettersLA = new JLabel("Tried letters:");
JLabel triesLeftLA = new JLabel("Tries remaining:");
private String[] wordList = {"computer","java","activity","alaska","appearance","article",
"automobile","basket","birthday","canada","central","character","chicken","chosen",
"cutting","daily","darkness","diagram","disappear","driving","effort","establish","exact",
"establishment","fifteen","football","foreign","frequently","frighten","function","gradually",
"hurried","identity","importance","impossible","invented","italian","journey","lincoln",
"london","massage","minerals","outer","paint","particles","personal","physical","progress",
"quarter","recognise","replace","rhythm","situation","slightly","steady","stepped",
"strike","successful","sudden","terrible","traffic","unusual","volume","yesterday" };
public String mysteryWord;
public int lives;
private boolean finished = false;
private boolean won = false;
private Button a[];
public boolean used[] = new boolean[26];
public static void main (String[] args) {
Hangman gui = new Hangman();
gui.go();
}
class myDrawPanel extends JPanel {
public void paintComponent(Graphics g) {
setBackground(Color.white);
g.setColor(Color.gray);
g.fillRect(50, 200, 150, 20);
g.fillRect(90,20,10,200);
g.fillRect(90,20,60,10);
g.setColor(Color.black);
g.fillRect(145,20,5,25);
g.setColor(Color.green);
if (lives < 6 )
g.drawOval(132,45,30,30);
if (lives < 5 )
g.drawLine(147,75,147,100);
if (lives < 4 )
g.drawLine(147,100,167,133);
if (lives < 3 )
g.drawLine(147,100,127,133);
if (lives < 2 )
g.drawLine(147,75,167,85);
if (lives < 1 )
g.drawLine(147,75,127,85);
StringBuffer guessed = new StringBuffer();
for (int cl = 0; cl < mysteryWord.length(); cl++) {
if (used[(int)mysteryWord.charAt(cl)-'a'])
guessed.append(mysteryWord.charAt(cl));
else
guessed.append("*");
}
currentWordLA.setText("Current word: " + guessed.toString());
if (lives < 1) {
g.setColor(Color.white);
g.fillRect(70, 200, 200, 30);
g.setColor(Color.black);
g.drawString(mysteryWord.toString(),75,230);
Font fff = new Font("Helvetica",Font.BOLD,36);
g.setFont(fff);
g.setColor(Color.red);
g.drawString("You lose!",200,100);
//finished = true;
}
if (won) {
Font fff = new Font("Helvetica",Font.BOLD,36);
g.setFont(fff);
// Color red=new Color.red
g.setColor(Color.red);
g.drawString("You Win!",200,100);
//finished = true;
}
}
}
public void go() {
///////////////////////DESIGN BEGIN//////////////////////////////////////////////
frame = new JFrame("Hangman");
JPanel topPanel = new JPanel();
myDrawPanel noosePanel = new myDrawPanel();
JPanel bottomPanel = new JPanel();
JPanel scorePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout( new GridLayout( 2, 0) );
bottomPanel.setLayout( new GridLayout( 0, 2) );
scorePanel.setSize(20,100);
noosePanel.setBorder(BorderFactory.createTitledBorder("Your progress."));
topPanel.setBorder(BorderFactory.createTitledBorder("Your arsenal."));
scorePanel.setBorder(BorderFactory.createTitledBorder("Your score."));
frame.add(topPanel);
frame.add(bottomPanel);
bottomPanel.add(scorePanel);
bottomPanel.add(noosePanel);
//Just the stats panel.
JButton restart = new JButton("Reset");
currentWordLA.setFont(new Font("Verdana", Font.PLAIN, 10));
currentWordLA.setForeground(Color.black);
triedLettersLA.setFont(new Font("Verdana", Font.PLAIN, 10));
triedLettersLA.setForeground(Color.black);
triesLeftLA.setFont(new Font("Verdana", Font.PLAIN, 10));
triesLeftLA.setForeground(Color.black);
restart.setFont(new Font("Verdana", Font.PLAIN, 16));
restart.setForeground(Color.red);
stats.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(20,0,0,0);
c.anchor = GridBagConstraints.LINE_START;
stats.add(currentWordLA, c);
c.gridx = 0;
c.gridy = 1;
c.anchor = GridBagConstraints.LINE_START;
stats.add(triedLettersLA, c);
c.gridx = 0;
c.gridy = 2;
c.anchor = GridBagConstraints.LINE_START;
stats.add(triesLeftLA, c);
c.gridx = 0;
c.gridy = 3;
c.anchor = GridBagConstraints.LINE_START;
stats.add(restart, c);
scorePanel.add(stats);
///////////////////////DESIGN END//////////////////////////////////////////////
///////////////////////ALPHABET BEGIN//////////////////////////////////////////
int i;
StringBuffer buffer;
a = new Button[26];
topPanel.setLayout( new GridLayout( 4,0, 10, 10) );
for (i = 0; i <26; i++) {
buffer = new StringBuffer();
buffer.append((char)(i+'a'));
a[i] = new Button(buffer.toString());
a[i].setSize(100,100);
a[i].addActionListener( this );
topPanel.add(a[i]);
}
///////////////////////ALPHABET END//////////////////////////////////////////
//Just shows the entire window.
frame.setSize(500, 500);
frame.setResizable(false);
frame.setVisible(true);
//////////////////////GAMEPLAY BEGIN////////////////////////////////////////
lives = 6;
triesLeftLA.setText("Tries remaining: " + lives);
mysteryWord = wordGen();
}
//Returns a random word from the wordList bank.
private String wordGen() {
return wordList[0 + (int)(Math.random() * ((63 - 0) + 1)) ]; //Make sure to set these to nonprinted chars eventually
}
public void consultWord(int letter) {
if (finished == false) {
boolean found = false;
boolean www = false;
if (used[letter] = false) {
System.out.println("test");
for (int cl = 0 ; cl < mysteryWord.length(); cl++) {
if (mysteryWord.charAt(cl)==((char)(letter + 'a'))) {
found = true;
}
}
if (found == false) {
lives = lives - 1;
triesLeftLA.setText ("Tries remaining: " + lives);
}
}
used[letter] = true;
for (int cl = 0; cl < mysteryWord.length(); cl++) {
if (!used[(int)(mysteryWord.charAt(cl)) - 'a']){
www = true;
}
}
if (www == false) {
won = true;
}
frame.repaint();
}
}
public void actionPerformed( ActionEvent e) {
int i;
for (i = 0; i < 26; i++) {
if (e.getSource() == a[i]) {
consultWord(i); }
}
}
}
Make that:
if (used[letter] == false) {
System.out.println("test");
if (used[letter] = false) {
You just set used[letter] to false. Try ==
Of course, to avoid this typo you shouldn't be using == but rather ...
if (!used[letter]) {

adding controls dynamically

how to add dynamically a menupanel with menuitems inside a accordion using coolite controls toolkit.
you can try my sample here :
private void CreateMenu(int index, string title, string url, MenuPanel menuPanel, Panel panel)
{
MenuItem menuItem = new MenuItem();
menuItem.ID = "MenuItem" + index;
menuItem.Text = title;
menuItem.Listeners.Click.Handler += "addTab(#{TabPanel1},#{" + menuPanel.ID + "},'MenuItem" + index + "',' " + title + "',' " + url + "');";
menuItem.Icon = Icon.ApplicationForm;
menuPanel.Menu.Items.Add(menuItem);
panel.BodyControls.Add(menuPanel);
Accordion1.Items.Add(panel);
}
private void PopulateMenus()
{
string[] menus = new string[] { null, "Menu 1", null, "Menu 2"};
MenuPanel menuPanel = null;
Panel panel = null;
for (int i = 0; i < menus.Length; i++)
{
if (menus[i] == null)
{
panel = new Panel();
panel.AutoScroll = true;
panel.ID = "Menu" + i;
panel.Title = menus[i + 1];
panel.Border = false;
panel.BodyStyle = "padding:6px;";
panel.Icon = Icon.ApplicationCascade;
menuPanel = new MenuPanel();
menuPanel.AutoScroll = true;
menuPanel.ID = "MenuPanel" + i;
menuPanel.Border = false;
menuPanel.BodyStyle = "padding:6px;";
continue;
}
CreateMenu(i, "Sub-" + menus[i], "www.test.com", menuPanel, panel);
}
}
Hope it helps.