Sort Custom Objects Using C++ STL

Ankith Reddy
Updated on 12-Feb-2020 06:19:23

13K+ Views

You can sort a vector of custom objects using the C++ STL function std::sort. The sort function has an overloaded form that takes as arguments first, last, comparator. The first and last are iterators to first and last elements of the container. The comparator is a predicate function that can be used to tell how to sort the container. example#include #include #include using namespace std; struct MyStruct {    int key;    string data;    MyStruct(int key, string data) {       this -> key = key;       this -> data = data;    } }; int ... Read More

Select Different Cells of a JTable Programmatically in Java

raja
Updated on 12-Feb-2020 06:17:43

1K+ Views

A JTable is a subclass of JComponent class and it can be used to create a table with information displayed in multiple rows and columns. When a value is selected from a JTable, a TableModelEvent is generated, which is handled by implementing a TableModelListener interface.In general, a user can select the rows and columns manually in a JTable, we can also select different cells of a JTable programmatically using setRowSelectionInterval() and setColumnSelectionInterval() methods of JTable class.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class JTableCellSelectionTest extends JFrame {    private JTable table;    public JTableCellSelectionTest() {       setTitle("JTableCellSelection Test");       Object[][] data = ... Read More

What are Forward Declarations in C++

Abhinaya
Updated on 12-Feb-2020 06:14:19

543 Views

Forward declaration lets the code following the declaration know that there is are classes with the name Person. This satisfies the compiler when it sees these names used. Later the linker will find the definition of the classes. exampleClass Person; void myFunc(Person p1) {    // ... } Class Person {    // Class definition here };So in this case when the compiler encounters myFunc, it'll know that it's going to encounter this class somewhere down in the code. This can be used in cases where code using the class is placed/included before the code containing the class definition.

Detect Value Change of a JSlider in Java

raja
Updated on 12-Feb-2020 05:32:30

1K+ Views

A JSlider is a subclass of JComponent class and it is similar to scroll bar which allows the user to select a numeric value from a specified range of integer values. A JSlider has a knob which can slide on a range of values and can be used to select a particular value. and it can generate a ChangeListener interface.We can detect the value changed when the slider is moved horizontally using the Graphics2D class and override paint() method.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class ValueChangeJSliderTest extends JFrame {    private JSlider slider;    public ValueChangeJSliderTest() { ... Read More

Get List of Columns from Another Database Table in SQL

mkotla
Updated on 12-Feb-2020 05:24:22

106 Views

It can be done with the SHOW COLUMNS statement. Its Syntax would be as follows:SyntaxSHOW COLUMNS FROM tab_name IN db_nameHere,  tab_name is the name of the table from which we want to see the list of columns.Db_name is the name of the database, in which the table is storedExampleIn the example, we are currently using the database ‘query’ and getting the list of columnsfrom a table named ‘arena’ stored in MySQL ‘database’:mysql> SHOW COLUMNS FROM arena IN mysql\G *************************** 1. row ***************************   Field: id    Type: int(10) unsigned zerofill    Null: NO     Key: PRI Default: NULL Extra ... Read More

C++ Standards Support in GCC

Vrundesha Joshi
Updated on 11-Feb-2020 12:54:12

1K+ Views

GCC supports different dialects of C++, corresponding to the multiple published ISO standards. Which standard it implements can be selected using the -std= command-line option.C++98 − GCC has full support for the 1998 C++ standard as modified in 2003 and renamed to C++03 and some later defect reports.C++11 − GCC 4.8.1 was the first complete implementation of the 2011 C++ standard, previously known as C++0x.C++14 − GCC has full support for the latest revision of the C++ standard, which was published in 2014.C++17 − GCC has experimental support for the next revision of the C++ standard, which is expected to ... Read More

What are Aggregates and PODs in C++

George John
Updated on 11-Feb-2020 12:49:57

783 Views

POD is an acronym in C++ that means plain old data. It is a class/struct that ONLY has member variables and no methods, constructors, destructors, virtual functions, etc. For example, Example#include using namespace std; // POD struct MyStruct {    int key;    string data; }; int main() {    struct MyStruct s;    s.key = 1;    s.data = "hello";    return 0; }The struct MyStruct has no user defined ctor, dtor, etc and hence is a POD.An aggregate is an array or a class with no user-declared constructors, no private or protected non-static data members, no base ... Read More

Detect Double Click Events of JTable Row in Java

raja
Updated on 11-Feb-2020 12:07:15

4K+ Views

A JTable is a subclass of JComponent for displaying complex data structures. A JTable can follow the Model View Controller (MVC) design pattern for displaying the data in rows and columns. A JTable can generate TableModelListener, TableColumnModelListener, ListSelectionListener, CellEditorListener and RowSorterListener interfaces. We can detect the double click events of a JTable by using a MouseAdapter class or MouseListener interface. We can set the getClickCount() value to '2' of a MouseEvent class for detecting the double click events of a JTable.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; public final class DoublClickJTableRowTest extends JFrame {    private JTable table;    private JScrollPane scrollPane;    public DoublClickJTableRowTest() {   ... Read More

C++ vs C++0x vs C++11 vs C++98

Smita Kapse
Updated on 11-Feb-2020 11:15:38

2K+ Views

C++98 was the first edition of the C++ standard. It had defined all the basic language constructs, the STL, and the standard library.C++03 was the next revision to this standard. This was majorly a considered a bugfix for the standard as it corrected 92 core language defect reports, 125 library defect reports, and included only one new language feature: value initialization.C++0x was the name of the work in progress that was expected to complete by 2008-09 but finally completed in 2011.C++11 was the modern C++ standard published in 2011. This brought many major extensions and improvements to the existing language. ... Read More

Importance of JViewport Class in Java

raja
Updated on 11-Feb-2020 11:11:40

500 Views

JViewportA JViewport class defines the basic scrolling model and it is designed to support both logical scrolling and pixel-based scrolling.The viewport's child called the view is scrolled by calling JViewport.setViewPosition() method.A JViewport class supports logical scrolling, that is a kind of scrolling in which view coordinates are not pixels.To support a logical scrolling, JViewport defines a small set of methods that can be used to define the geometry of a viewport and a view. By default, these methods just report the pixel dimensions of the viewport and view.Exampleimport java.awt.*; import javax.swing.*; public class JViewportTest extends JFrame {    public JViewportTest() {       setTitle("JViewport Test"); ... Read More

Advertisements