http://hanynowsky.wordpress.com/2012/06/10/create-gtk-based-java-applications-on-linux-with-java-gtk-library/
http://java-gnome.sourceforge.net/
http://www.linuxjournal.com/article/8111?page=0,1
http://zetcode.com/gui/javagnome/
http://danny.damours.net/wordpress/creating-a-gtk-app-in-java-using-java-gnome
terça-feira, 27 de novembro de 2012
segunda-feira, 26 de novembro de 2012
Gtk exemplos
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget* window; // cria objeto window
window = gtk_window_new(GTK_WINDOW_TOPLEVEL); // tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show(window); // mostra aplicação
gtk_main(); // loop do gtk
return 0;
}
/******************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *label; // cria objeto window e label
window = gtk_window_new(GTK_WINDOW_TOPLEVEL); // tipo de janela
label = gtk_label_new("Hello World"); // cria objeto label com texto Hello World
gtk_label_set_text(GTK_LABEL(label), "World Hello");// modifica texto
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
gtk_container_add(GTK_CONTAINER(window), label);// adiciona o label na janela
gtk_widget_show_all(window); // mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*******************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
static void button_clicked(GtkWidget* widget, gpointer data)
{
g_print("Button is pressed\n");
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *button;// cria objeto window e button
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
button = gtk_button_new_with_label("Click me");
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(button,"clicked", G_CALLBACK(button_clicked), NULL);
// g_signal_connect(button,"clicked", G_CALLBACK(gtk_main_quit), NULL);
gtk_container_add(GTK_CONTAINER(window), button);
gtk_widget_set_size_request(window, 300, 300);
gtk_window_set_title(GTK_WINDOW(window),"Hello World");
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
static void button_clicked(GtkWidget* widget, gpointer data)
{
gtk_label_set_text(GTK_LABEL(data), "you clicked the button");
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window,*label,*button,*vbox;//Cria objeto window, label,button e vbox
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
label = gtk_label_new("Hello World");
button = gtk_button_new_with_label("Click me");
g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), (gpointer)label);
vbox = gtk_vbox_new(0, 0);
gtk_box_pack_start(GTK_BOX(vbox), label, 1, 1, 0);
gtk_box_pack_start(GTK_BOX(vbox), button, 1, 1, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window,*label,*button,*table;//Cria objeto window,label,button e table
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
table = gtk_table_new(2, 2, 0); //rows, columns, honogenous
button = gtk_button_new_with_mnemonic("_Button");
label = gtk_label_new("Hello World");
gtk_table_attach(GTK_TABLE(table), label, 0,1,0,1, GTK_FILL, GTK_FILL, 0,0);
gtk_table_attach(GTK_TABLE(table), button, 1,2,0,1, GTK_FILL, GTK_FILL, 0,0);
button = gtk_button_new_with_mnemonic("_Button 2");
label = gtk_label_new("Hello World 2");
gtk_table_attach(GTK_TABLE(table), label, 0,1,1,2, GTK_FILL, GTK_FILL, 0,0);
gtk_table_attach(GTK_TABLE(table), button, 1,2,1,2, GTK_FILL, GTK_FILL, 0,0);
gtk_container_add(GTK_CONTAINER(window), table);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
static void button_clicked(GtkWidget *widget, gpointer data)
{
g_print("%s\n", gtk_entry_get_text(GTK_ENTRY(data)));
// gtk_entry_set_text(GTK_ENTRY(data),"Text printed");
gtk_editable_select_region(GTK_EDITABLE(data), 0,-1); // text from 0 to the end
gtk_editable_copy_clipboard(GTK_EDITABLE(data));
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window,*entry,*button,*hbox; //Cria objeto window,entry,button,hbox
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
entry = gtk_entry_new();
button = gtk_button_new_with_mnemonic("_Write text");
g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), entry);
g_signal_connect(entry, "activate", G_CALLBACK(button_clicked), entry); // press enter to call funtion
hbox = gtk_hbox_new(0,0);
gtk_box_pack_start(GTK_BOX(hbox), entry, 0,0,0);
gtk_box_pack_start(GTK_BOX(hbox), button, 0,0,0);
gtk_container_add(GTK_CONTAINER(window), hbox);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
static void check_state(GtkWidget* widget, gpointer data)
{
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
{
g_print("Toggle button activated\n");
}else
{
g_print("Toggle button not activated\n");
}
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *toggle, *vbox;//Cria objeto window,toggle,vbox
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
vbox = gtk_vbox_new(0,0);
toggle = gtk_toggle_button_new_with_mnemonic("_Toggle 1");
// toggle = gtk_check_button_new_with_mnemonic("_Toggle 1");
gtk_box_pack_start(GTK_BOX(vbox), toggle, 0,0,0);
g_signal_connect(toggle, "toggled", G_CALLBACK(check_state), NULL);
toggle = gtk_toggle_button_new_with_mnemonic("_Toggle 2");
// toggle = gtk_check_button_new_with_mnemonic("_Toggle 2");
gtk_box_pack_start(GTK_BOX(vbox), toggle, 0,0,0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), true);
g_signal_connect(toggle, "toggled", G_CALLBACK(check_state), NULL);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
#include <cstring>
static void toggled_func(GtkWidget* widget, gpointer data)
{
if(strcmp((char*)data, "1") == 0)
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
g_print("Button %s is set to active\n", (char*)data);
else
g_print("Button %s is set to deactive\n", (char*)data);
if(strcmp((char*)data, "2") == 0)
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
g_print("Button %s is set to active\n", (char*)data);
else
g_print("Button %s is set to deactive\n", (char*)data);
if(strcmp((char*)data, "3") == 0)
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
g_print("Button %s is set to active\n", (char*)data);
else
g_print("Button %s is set to deactive\n", (char*)data);
if(strcmp((char*)data, "4") == 0)
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
g_print("Button %s is set to active\n", (char*)data);
else
g_print("Button %s is set to deactive\n", (char*)data);
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window,*radio,*radio2,*hbox;//Cria objeto window,radio,radio2,hbox
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
hbox = gtk_hbox_new(0,0);
radio = gtk_radio_button_new_with_label(NULL, "label 1");
gtk_box_pack_start(GTK_BOX(hbox), radio, 0,0,0);
g_signal_connect(radio, "toggled", G_CALLBACK(toggled_func), (gpointer)"1");
radio2 = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio)), "label 2");
gtk_box_pack_start(GTK_BOX(hbox), radio2, 0,0,0);
g_signal_connect(radio2, "toggled", G_CALLBACK(toggled_func), (gpointer)"2");
radio2 = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio)), "label 3");
gtk_box_pack_start(GTK_BOX(hbox), radio2, 0,0,0);
g_signal_connect(radio2, "toggled", G_CALLBACK(toggled_func), (gpointer)"3");
radio2 = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio)), "label 4");
gtk_container_add(GTK_CONTAINER(window),hbox);
gtk_box_pack_start(GTK_BOX(hbox), radio2, 0,0,0);
g_signal_connect(radio2, "toggled", G_CALLBACK(toggled_func), (gpointer)"4");
// gtk_container_add(GTK_CONTAINER(window), hbox); // ? Runtime-Warning ?
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
#include <cstring>
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *button;// cria objeto window,button
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
button = gtk_button_new_from_stock(GTK_STOCK_APPLY);
gtk_container_add(GTK_CONTAINER(window), button);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
#include <cstring>
static float percent = 0.0;
static gboolean inc_progress(gpointer data)
{
percent += 0.05;
if(percent > 1.0)
percent = 0.0;
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(data), percent);
char c[3];
sprintf(c, "%d%%", static_cast<int>(percent*100));
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(data), c);
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv);//inicializa gtk
GtkWidget *window, *progress;//Cria objeto window,progress
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
progress = gtk_progress_bar_new();
// gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), "50%");
// gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(progress), GTK_PROGRESS_TOP_TO_BOTTOM);
g_timeout_add(200, inc_progress, progress); // 300 ms
gtk_container_add(GTK_CONTAINER(window), progress);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
#include <string>
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *notebook, *label, *label2;//Cria objeto window,notebook,label,label2
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
notebook = gtk_notebook_new();
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_BOTTOM);
for(int i = 0; i < 5; i += 1)
{
std::string s = "This is just a test of the notebook.\nIn this example you can learn it.%nThis is the page ";
s += static_cast<char>(49+i);
label = gtk_label_new(s.c_str());
s = "Page ";
s += static_cast<char>(49+i);
label2 = gtk_label_new(s.c_str());
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), label, label2);
}
gtk_container_add(GTK_CONTAINER(window), notebook);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
#include <string>
static void open_dialog(GtkWidget* button, gpointer window)
{
GtkWidget *dialog, *label;// cria objeto dialog e label
dialog = gtk_dialog_new_with_buttons("Dialog", GTK_WINDOW(window), GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_OK, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
label = gtk_label_new("You clicked the button");
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog) -> vbox), label, 0,0,0);
gtk_widget_show_all(dialog);
gint response = gtk_dialog_run(GTK_DIALOG(dialog));
if(response == GTK_RESPONSE_OK)
g_print("You klicked OK\n");
else
g_print("You klicked Cancel\n");
gtk_widget_destroy(dialog);
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *button;// cria objeto window e button
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
button = gtk_button_new_with_label("Click me");
g_signal_connect(button, "clicked", G_CALLBACK(open_dialog), window);
gtk_container_set_border_width(GTK_CONTAINER(window), 100);
gtk_container_add(GTK_CONTAINER(window), button);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
#include <cstring>
static void menu_response(GtkWidget* menu_item, gpointer data)
{
if(strcmp(gtk_menu_item_get_label(GTK_MENU_ITEM(menu_item)), "New") == 0) // equal
{
g_print("You pressed New\n");
}
if(strcmp(gtk_menu_item_get_label(GTK_MENU_ITEM(menu_item)), "Exit") == 0) // equal
{
g_print("You pressed Exit\n");
}
if(strcmp(gtk_menu_item_get_label(GTK_MENU_ITEM(menu_item)), "About") == 0) // equal
{
g_print("You pressed About\n");
}
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *menu_bar, *menu_item, *file_menu, *help_menu, *vbox, *button;//Cria objeto window,label,menu_bar,menu_item,file_menu,help_menu,vbox, button
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
menu_bar = gtk_menu_bar_new();
file_menu = gtk_menu_new();
help_menu = gtk_menu_new();
menu_item = gtk_menu_item_new_with_label("File");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), file_menu);
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), menu_item);
menu_item = gtk_menu_item_new_with_label("Help");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), help_menu);
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), menu_item);
menu_item = gtk_menu_item_new_with_label("New");
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), menu_item);
g_signal_connect(menu_item, "activate", G_CALLBACK(menu_response), NULL);
menu_item = gtk_menu_item_new_with_label("Exit");
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), menu_item);
g_signal_connect(menu_item, "activate", G_CALLBACK(menu_response), NULL);
menu_item = gtk_menu_item_new_with_label("About");
gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), menu_item);
g_signal_connect(menu_item, "activate", G_CALLBACK(menu_response), NULL);
vbox = gtk_vbox_new(0,0);
button = gtk_button_new_with_label("This is a Button");
gtk_box_pack_start(GTK_BOX(vbox), menu_bar,0,0,0);
gtk_box_pack_start(GTK_BOX(vbox), button,0,0,0);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget* window; // cria objeto window
window = gtk_window_new(GTK_WINDOW_TOPLEVEL); // tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show(window); // mostra aplicação
gtk_main(); // loop do gtk
return 0;
}
/******************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *label; // cria objeto window e label
window = gtk_window_new(GTK_WINDOW_TOPLEVEL); // tipo de janela
label = gtk_label_new("Hello World"); // cria objeto label com texto Hello World
gtk_label_set_text(GTK_LABEL(label), "World Hello");// modifica texto
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
gtk_container_add(GTK_CONTAINER(window), label);// adiciona o label na janela
gtk_widget_show_all(window); // mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*******************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
static void button_clicked(GtkWidget* widget, gpointer data)
{
g_print("Button is pressed\n");
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *button;// cria objeto window e button
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
button = gtk_button_new_with_label("Click me");
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(button,"clicked", G_CALLBACK(button_clicked), NULL);
// g_signal_connect(button,"clicked", G_CALLBACK(gtk_main_quit), NULL);
gtk_container_add(GTK_CONTAINER(window), button);
gtk_widget_set_size_request(window, 300, 300);
gtk_window_set_title(GTK_WINDOW(window),"Hello World");
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
static void button_clicked(GtkWidget* widget, gpointer data)
{
gtk_label_set_text(GTK_LABEL(data), "you clicked the button");
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window,*label,*button,*vbox;//Cria objeto window, label,button e vbox
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
label = gtk_label_new("Hello World");
button = gtk_button_new_with_label("Click me");
g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), (gpointer)label);
vbox = gtk_vbox_new(0, 0);
gtk_box_pack_start(GTK_BOX(vbox), label, 1, 1, 0);
gtk_box_pack_start(GTK_BOX(vbox), button, 1, 1, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window,*label,*button,*table;//Cria objeto window,label,button e table
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
table = gtk_table_new(2, 2, 0); //rows, columns, honogenous
button = gtk_button_new_with_mnemonic("_Button");
label = gtk_label_new("Hello World");
gtk_table_attach(GTK_TABLE(table), label, 0,1,0,1, GTK_FILL, GTK_FILL, 0,0);
gtk_table_attach(GTK_TABLE(table), button, 1,2,0,1, GTK_FILL, GTK_FILL, 0,0);
button = gtk_button_new_with_mnemonic("_Button 2");
label = gtk_label_new("Hello World 2");
gtk_table_attach(GTK_TABLE(table), label, 0,1,1,2, GTK_FILL, GTK_FILL, 0,0);
gtk_table_attach(GTK_TABLE(table), button, 1,2,1,2, GTK_FILL, GTK_FILL, 0,0);
gtk_container_add(GTK_CONTAINER(window), table);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
static void button_clicked(GtkWidget *widget, gpointer data)
{
g_print("%s\n", gtk_entry_get_text(GTK_ENTRY(data)));
// gtk_entry_set_text(GTK_ENTRY(data),"Text printed");
gtk_editable_select_region(GTK_EDITABLE(data), 0,-1); // text from 0 to the end
gtk_editable_copy_clipboard(GTK_EDITABLE(data));
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window,*entry,*button,*hbox; //Cria objeto window,entry,button,hbox
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
entry = gtk_entry_new();
button = gtk_button_new_with_mnemonic("_Write text");
g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), entry);
g_signal_connect(entry, "activate", G_CALLBACK(button_clicked), entry); // press enter to call funtion
hbox = gtk_hbox_new(0,0);
gtk_box_pack_start(GTK_BOX(hbox), entry, 0,0,0);
gtk_box_pack_start(GTK_BOX(hbox), button, 0,0,0);
gtk_container_add(GTK_CONTAINER(window), hbox);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
static void check_state(GtkWidget* widget, gpointer data)
{
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
{
g_print("Toggle button activated\n");
}else
{
g_print("Toggle button not activated\n");
}
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *toggle, *vbox;//Cria objeto window,toggle,vbox
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
vbox = gtk_vbox_new(0,0);
toggle = gtk_toggle_button_new_with_mnemonic("_Toggle 1");
// toggle = gtk_check_button_new_with_mnemonic("_Toggle 1");
gtk_box_pack_start(GTK_BOX(vbox), toggle, 0,0,0);
g_signal_connect(toggle, "toggled", G_CALLBACK(check_state), NULL);
toggle = gtk_toggle_button_new_with_mnemonic("_Toggle 2");
// toggle = gtk_check_button_new_with_mnemonic("_Toggle 2");
gtk_box_pack_start(GTK_BOX(vbox), toggle, 0,0,0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), true);
g_signal_connect(toggle, "toggled", G_CALLBACK(check_state), NULL);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
#include <cstring>
static void toggled_func(GtkWidget* widget, gpointer data)
{
if(strcmp((char*)data, "1") == 0)
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
g_print("Button %s is set to active\n", (char*)data);
else
g_print("Button %s is set to deactive\n", (char*)data);
if(strcmp((char*)data, "2") == 0)
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
g_print("Button %s is set to active\n", (char*)data);
else
g_print("Button %s is set to deactive\n", (char*)data);
if(strcmp((char*)data, "3") == 0)
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
g_print("Button %s is set to active\n", (char*)data);
else
g_print("Button %s is set to deactive\n", (char*)data);
if(strcmp((char*)data, "4") == 0)
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
g_print("Button %s is set to active\n", (char*)data);
else
g_print("Button %s is set to deactive\n", (char*)data);
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window,*radio,*radio2,*hbox;//Cria objeto window,radio,radio2,hbox
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
hbox = gtk_hbox_new(0,0);
radio = gtk_radio_button_new_with_label(NULL, "label 1");
gtk_box_pack_start(GTK_BOX(hbox), radio, 0,0,0);
g_signal_connect(radio, "toggled", G_CALLBACK(toggled_func), (gpointer)"1");
radio2 = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio)), "label 2");
gtk_box_pack_start(GTK_BOX(hbox), radio2, 0,0,0);
g_signal_connect(radio2, "toggled", G_CALLBACK(toggled_func), (gpointer)"2");
radio2 = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio)), "label 3");
gtk_box_pack_start(GTK_BOX(hbox), radio2, 0,0,0);
g_signal_connect(radio2, "toggled", G_CALLBACK(toggled_func), (gpointer)"3");
radio2 = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio)), "label 4");
gtk_container_add(GTK_CONTAINER(window),hbox);
gtk_box_pack_start(GTK_BOX(hbox), radio2, 0,0,0);
g_signal_connect(radio2, "toggled", G_CALLBACK(toggled_func), (gpointer)"4");
// gtk_container_add(GTK_CONTAINER(window), hbox); // ? Runtime-Warning ?
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
#include <cstring>
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *button;// cria objeto window,button
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
button = gtk_button_new_from_stock(GTK_STOCK_APPLY);
gtk_container_add(GTK_CONTAINER(window), button);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
#include <cstring>
static float percent = 0.0;
static gboolean inc_progress(gpointer data)
{
percent += 0.05;
if(percent > 1.0)
percent = 0.0;
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(data), percent);
char c[3];
sprintf(c, "%d%%", static_cast<int>(percent*100));
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(data), c);
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv);//inicializa gtk
GtkWidget *window, *progress;//Cria objeto window,progress
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
progress = gtk_progress_bar_new();
// gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), "50%");
// gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(progress), GTK_PROGRESS_TOP_TO_BOTTOM);
g_timeout_add(200, inc_progress, progress); // 300 ms
gtk_container_add(GTK_CONTAINER(window), progress);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
#include <string>
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *notebook, *label, *label2;//Cria objeto window,notebook,label,label2
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
notebook = gtk_notebook_new();
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_BOTTOM);
for(int i = 0; i < 5; i += 1)
{
std::string s = "This is just a test of the notebook.\nIn this example you can learn it.%nThis is the page ";
s += static_cast<char>(49+i);
label = gtk_label_new(s.c_str());
s = "Page ";
s += static_cast<char>(49+i);
label2 = gtk_label_new(s.c_str());
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), label, label2);
}
gtk_container_add(GTK_CONTAINER(window), notebook);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
#include <string>
static void open_dialog(GtkWidget* button, gpointer window)
{
GtkWidget *dialog, *label;// cria objeto dialog e label
dialog = gtk_dialog_new_with_buttons("Dialog", GTK_WINDOW(window), GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_OK, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
label = gtk_label_new("You clicked the button");
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog) -> vbox), label, 0,0,0);
gtk_widget_show_all(dialog);
gint response = gtk_dialog_run(GTK_DIALOG(dialog));
if(response == GTK_RESPONSE_OK)
g_print("You klicked OK\n");
else
g_print("You klicked Cancel\n");
gtk_widget_destroy(dialog);
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *button;// cria objeto window e button
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
button = gtk_button_new_with_label("Click me");
g_signal_connect(button, "clicked", G_CALLBACK(open_dialog), window);
gtk_container_set_border_width(GTK_CONTAINER(window), 100);
gtk_container_add(GTK_CONTAINER(window), button);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
/*********************************************************************************/
//http://www.youtube.com/user/thecplusplusguy
//Thanks for the typed in code to Tapit85
#include <gtk/gtk.h>//biblioteca do gtk
#include <cstring>
static void menu_response(GtkWidget* menu_item, gpointer data)
{
if(strcmp(gtk_menu_item_get_label(GTK_MENU_ITEM(menu_item)), "New") == 0) // equal
{
g_print("You pressed New\n");
}
if(strcmp(gtk_menu_item_get_label(GTK_MENU_ITEM(menu_item)), "Exit") == 0) // equal
{
g_print("You pressed Exit\n");
}
if(strcmp(gtk_menu_item_get_label(GTK_MENU_ITEM(menu_item)), "About") == 0) // equal
{
g_print("You pressed About\n");
}
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv); //inicializa gtk
GtkWidget *window, *menu_bar, *menu_item, *file_menu, *help_menu, *vbox, *button;//Cria objeto window,label,menu_bar,menu_item,file_menu,help_menu,vbox, button
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);// tipo de janela
/* evento que encerra aplicação */
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
menu_bar = gtk_menu_bar_new();
file_menu = gtk_menu_new();
help_menu = gtk_menu_new();
menu_item = gtk_menu_item_new_with_label("File");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), file_menu);
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), menu_item);
menu_item = gtk_menu_item_new_with_label("Help");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), help_menu);
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), menu_item);
menu_item = gtk_menu_item_new_with_label("New");
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), menu_item);
g_signal_connect(menu_item, "activate", G_CALLBACK(menu_response), NULL);
menu_item = gtk_menu_item_new_with_label("Exit");
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), menu_item);
g_signal_connect(menu_item, "activate", G_CALLBACK(menu_response), NULL);
menu_item = gtk_menu_item_new_with_label("About");
gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), menu_item);
g_signal_connect(menu_item, "activate", G_CALLBACK(menu_response), NULL);
vbox = gtk_vbox_new(0,0);
button = gtk_button_new_with_label("This is a Button");
gtk_box_pack_start(GTK_BOX(vbox), menu_bar,0,0,0);
gtk_box_pack_start(GTK_BOX(vbox), button,0,0,0);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(window);// mostra janela e todos componentes
gtk_main();// loop do gtk
return 0;
}
quarta-feira, 21 de novembro de 2012
Lazarus e freepascal
Links para estudar
download
free pascal
http://sourceforge.net/projects/freepascal/files/
Lazarus http://sourceforge.net/projects/lazarus/files/
Videos sobre Lazarus e free pascal
Instalando o Free Pascal no Linux
http://www.youtube.com/watch?v=siPLjRN7DwA
Hello World FreePascal
http://www.youtube.com/watch?v=bXusw_ycc8o
Hello World FreePascal e GTK no Linux
http://www.youtube.com/watch?v=p3sK0ZNOfvM
Exemplos FreePascal e GTK no Linux
http://www.youtube.com/watch?v=R0VPj8r_DKw
Instalando o Lazarus no Linux
http://www.youtube.com/watch?v=ZAnNDXY7reo
Programa com ListBox no Lazarus no Linux
http://www.youtube.com/watch?v=WWooRS6ggOw
Eventos no Lazarus no Linux
http://www.youtube.com/watch?v=u1L-HezeEk4
Lazarus MessageDlg no Linux
http://www.youtube.com/watch?v=i8Oc2V3Ebnw
Calculadora no Lazarus no Linux
http://www.youtube.com/watch?v=1HrhYA1OKHw
Lazarus e MySQL e ZEUS no Windows
http://www.youtube.com/watch?v=5jv6ZDpE6W4
http://www.youtube.com/watch?v=bMX4pdj5Blk
http://www.youtube.com/watch?v=9MNEJAjjzVU
Cadastro Simples Lazarus e Mysql Ubuntu
http://www.youtube.com/watch?v=z56Wp1GZpyI
http://www.youtube.com/watch?v=phPu6CertZk
http://www.youtube.com/watch?v=8YiRwa0OcBo
http://www.youtube.com/watch?v=i8Oc2V3Ebnw
http://www.youtube.com/watch?v=JIboUIpPHXg
http://www.youtube.com/watch?v=z56Wp1GZpyI
quarta-feira, 14 de novembro de 2012
GTKmm
Exemplo de Aplicação Gráfica em C++
A aplicação a seguir cria uma janela com um botão Hello World, que ao ser clicado imprime a mensagem "Hello World". A classe HelloWorld extende a classe Gtk::Window, adquirindo suas características. A função main instancia a janela e executa o programa.hello.h:
hello.cpp:#ifndef HELLO_H#define HELLO_H#include <gtkmm/button.h>#include <gtkmm/window.h>class HelloWorld : public Gtk::Window{public:HelloWorld();virtual ~HelloWorld();protected://Signal handlersvirtual void on_button_clicked();//Member widgetsGtk::Button m_button;};#endif
main.cpp:#include <iostream>#include "hello.h"HelloWorld::HelloWorld(): m_button("Hello World"){set_border_width(10);m_button.signal_clicked().connect(sigc::mem_fun(*this,&HelloWorld::on_button_clicked));add(m_button);m_button.show();}HelloWorld::~HelloWorld(){}void HelloWorld::on_button_clicked(){std::cout << "Hello World" << std::endl;}
#include <gtkmm/main.h>#include "hello.h"int main (int argc, char *argv[]){Gtk::Main kit(argc, argv);HelloWorld helloworld;Gtk::Main::run(helloworld);return 0;}
Compilação Passo a Passo
O compilador de C++ do GCC é o g++.$ g++ hello.cpp -c `pkg-config gtkmm-2.4 --cflags` $ g++ main.cpp -c `pkg-config gtkmm-2.4 --cflags` $ g++ main.o hello.o -o hello `pkg-config gtkmm-2.4 --libs` $ ./helloCaso você não saiba, o efeito da crase em trechos como `pkg-config gtkmm-2.4 --cflags`, é executar um outro programa e "colar" seu resultado na linha de comando, e só então executar o programa chamado no início da linha.
Aperte o botão "Hello World" algumas vezes e veja o resultado.
pkg-config
Retorna informações sobre bibliotecas instaladas no sistema, como parâmetros para linha de comando do gcc, estas informações vêm de arquivos .pc, instalados pelos pacotes lib*-dev. Arquivos .pc costumam ficar em /usr/lib/pkgconfigFaça Você Mesmo: observe a saída de pkg-config e o conteúdo do arquivo .pc da biblioteca gtkmm.
$ pkg-config gtkmm-2.4 --cflags --libs $ cat /usr/lib/pkgconfig/gtkmm-2.4.pc
https://www.youtube.com/watch?v=aYwZ1AgPoZY&feature=related
Tutorial C++ - 12 - Introdução a Classe e Objetos (Em Português)https://www.youtube.com/watch?v=-2xSAk5I-dY
Pascal gtkentry
http://fr.wikibooks.org/wiki/Programmation_GTK2_en_Pascal/GtkEntry
exemplo como tratar float em c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
float a;
float b = 0.1;
printf("Digite um numero.: ");
scanf("%f",&a);
fflush(stdin);
printf("A soma e.: %.2f\n",a+b);
system("PAUSE");
return 0;
}
Gtk+ e Math.h http://youtu.be/thl2RCWBOZY
#include <stdlib.h>
#include <gtk/gtk.h>
#include <math.h>
#include <stdio.h>
static void clique (GtkWidget *w, GtkWidget *p);
static void sair (GtkWidget *w, GtkWidget *p);
static void sair (GtkWidget *w, GtkWidget *p)
{
gtk_main_quit();
}
static void clique (GtkWidget *w, GtkWidget *p)
{
int num1=9;
g_printf("O botao foi clicado\n o valor.: %.2f",pow(num,2));
}
int main (int argc, char *argv[])
{
GtkWidget *janela,*botao;
/* Initialize GTK+ */
gtk_init (&argc, &argv);
/* Create the main window */
janela = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width (GTK_CONTAINER (Janela), 8);
gtk_window_set_title (GTK_WINDOW (janela), "Gtk+ e Math.h");
gtk_window_set_position (GTK_WINDOW (janela), GTK_WIN_POS_CENTER);
gtk_widget_realize (janela);
g_signal_connect (janela, "delete-event", G_CALLBACK(sair), NULL);
botao = gtk_button_new_with_label("Clique aqui");
gtk_container_add(GTK_CONTAINER(janela),botao);
g_signal_connect (G_OBJECT (botao), "clicked", G_CALLBACK (clique), NULL);
/* Enter the main loop */
gtk_widget_show_all (janela);
gtk_main ();
return 0;
}
http://homepages.dcc.ufmg.br/~joaoreis/Site%20de%20tutoriais/
Assinar:
Postagens (Atom)